Facebook离线墙贴不工作 - 二月破坏变化

时间:2013-04-11 17:09:53

标签: php facebook offline

任何人都可以帮助我解决这个问题,过去48小时我都在为此烦恼。

目的: 我想通过我的网站向我的朋友facebook墙发布一些信息。 一切都工作正常,但我现在收到错误:

Fatal error: Uncaught OAuthException: (#200) The user hasn't authorized the application to perform this action thrown in /home/abcd/public_html/front_apps/controllers/src/base_facebook.php on line 1039

我还想做的是,在我离线时,使用cron将其发布在朋友的Facebook墙上,并在每天上午12点之前发布。

我在这里使用PHP代码是代码:

<?php

$message = "Message goes here";
$link = "http://link.com/";
$picture = "http://link.com/1.jpg";
$sendTo = "my friend id";
$access_token = "access tocken";

require 'src/facebook.php';
$facebook = new Facebook(array(
      'appId'  => 'appId',
      'secret' => 'secret_ID',
    )); <br>

$attachment = array('message' => $message, 'link' => $link, 'picture' => $picture );
$api = "/$sendTo/feed/?access_token='.$access_token,";
$result = $facebook->api($api,'post', $attachment);

?>

2 个答案:

答案 0 :(得分:0)

由于facebook弃用了离线访问,您必须获得长期令牌(有效期为60天)并将其存储在您的服务器上!这是我正在使用的。

立即获取长期存在的令牌使用服务器端登录流程

$code = $_REQUEST["code"];

//get acces token from user
$token_url = "https://graph.facebook.com/oauth/access_token?"."client_id=".$config[‘appId’]."&redirect_uri=".urlencode($my_url)."&client_secret=".$config[‘secret’]."&code=".$code;

$response = file_get_contents($token_url);
$params = null;
parse_str($response, $params);

$token = $params['access_token']; //long live the token

并发布到用户墙

//construct the image URL
$url ="https://".$_SERVER['SERVER_NAME'].$event_data['path'];
$img_url = urlencode($url); //encode the URL
$text= urlencode($event_data['text']);

//post to user wall - picture and text 
$post_url= "https://graph.facebook.com/".$user_data['uid']."/photos?url=".$img_url."&message=".$text."&access_token=".$user_data['token']."&method=post";
$upload_photo = file_get_contents($post_url);

希望它有所帮助;)

答案 1 :(得分:0)

相关问题