1

我正在尝试创建一个脚本,该脚本无需登录用户即可在 facebook 页面上发布状态更新。当用户授予应用程序一次时,我的应用程序和页面都有 access_token ;但我总是得到错误

Fatal error:  Uncaught OAuthException: (#200) The user hasn't authorized the application to perform this action

尽管我已授予manage_pagespublish_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。

4

1 回答 1

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
于 2012-10-03T13:55:44.737 回答