我正在尝试创建一个脚本,在Facebook页面上发布状态更新,而无需登录用户。我已经为我的应用程序和用户授予应用程序一次的页面获得了access_token;但我总是得到错误
Fatal error: Uncaught OAuthException: (#200) The user hasn't authorized the application to perform this action
尽管我已授予 manage_pages 和 publish_stream 权限。 此外,如果我对页面使用access_token,我会收到错误
Fatal error: Uncaught OAuthException: Error validating access token: The session is invalid because the user logged out.
这是我使用的代码。
$facebook = new Facebook(array(
'appId' => 'XXX',
'secret' => 'XXXXXXXXXXX'
));
$post = array(
'message' => 'Message to user'/*,
access_token = "XXXXXXXX"*/
);
$feed = '/[PAGE_ID]/feed';
$post_id = $facebook->api($feed, "post", $post);
感谢。
修改:
我终于设法在用户断开连接时在用户页面上发布状态更新,我不得不通过服务器端身份验证方法生成access_token。
答案 0 :(得分:1)
以下是关于如何对页面进行FB发布的小代码:
你需要:
Your_authToken_for_User
列出项目
saved_fb_Page_Token
$facebook = $facebook = new Facebook(array(
'appId' => $fbAppId,
'secret' => $fbAppSecret,
'cookie' => true,
));
$facebook->setAccessToken("Your_authToken_for_User");
//Now your FB instance is authenticated.
$pages= $facebook->api('/me/accounts'); //use the current authenticated FB instance to grab Pages. If you already know your page ID , skip this.
//Assuming you have a pageid in $page_id,(the $page_id can be grabbed from the $pages array).
$attachment = array(
'access_token' => $saved_fb_Page_Token,
'message' => "foo",
'name' => "Bar",
'link' => "http://foo.bar",
'description' => "barfoo",
'picture' => "an image url here",
);
$facebook->api('/' . $page_id . '/feed', 'POST', $attachment);//post to fb page