1

谁能帮我解决这个问题,在过去的 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

另外我想做的是,当我离线时将其发布在我朋友的 Facebook 墙上,使用cron并在每天上午 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);

?>
4

2 回答 2

0

由于 facebook 已弃用 Offline Acces,您必须获得长寿令牌(有效期为 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);

希望能帮助到你 ;)

于 2013-04-11T22:29:23.170 回答