ds000001 2014-01-25 03: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-25 04: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.

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

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题