ds000001 2014-01-24 19:41
浏览 36
已采纳

发布到我的Facebook公司页面作为页面

I've been succesfully been using the following code to post to my fan page AS the page:

    //Call Facebook API
$facebook = new Facebook(array(
  'appId'  => $appId,
  'secret' => $appSecret,
  'cookie' => true,
));

$fbPost = array('access_token' => $fbToken, 'message' => $string2 ,'name' => $string2, 'description'=> $description,'link'=> $unshort);

try{
    //This is to post a link!
    $postResult = $facebook->api('/xxxxxxxxxxxxxxx/feed', 'POST', $fbPost );
    echo 'Posted';
    echo '<br />';          
} catch (Exception $e){
    echo 'Didnt Work';
    echo '<br />';          
    echo $e->getMessage();
}

However, my account was temporarily blocked by facebook (don't ask... malicious competitor). After clearing up the situation, the ban on my account has been lifted and I can post on my fan page, however my above PHP script will only post as myself on the page, NOT as the page itself.

After the ban was lifted I had to renew my access tokens, but did this as normal. Since my code hasn't changed, Im guessing it has to do with how I renewd my access token, but everything seems to be in order.

Any ideas as to why my code is now posting as me (the admin) rather then as the page itself?

Thank you!

  • 写回答

1条回答 默认 最新

  • doubi3929 2014-01-24 20:14
    关注

    I think that's because your Access Token is missing the manage_pages. Try to debug your Access Token.

    According to the Page Feed documentation, a Page Access Token with publish_actions permission can be used to publish new posts on behalf of that page. To obtain a page access token you need to start by obtaining a user access token and asking for the manage_pages permission. Once you have the user access token you then get the page access token via the Graph API, by making a GET request to /{user-id}/accounts. This will give you a Page Access Token which will allow you to publish as a Page.

    For the page Access Token, you can simply do something like:

    $userAccounts = $facebook->api('/me/accounts');
    

    And this will give you the following output:

    {
      "data": [
        {
          "category": "Product/service",
          "name": "Sample Page",
          "access_token": "{access-token}",
          "id": "1234567890",
          "perms": [
            "ADMINISTER",
            "EDIT_PROFILE",
            "CREATE_CONTENT",
            "MODERATE_CONTENT",
            "CREATE_ADS",
            "BASIC_ADMIN"
          ]
        }, 
    }
    

    More details can be found at: Page Tokens.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部