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.

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

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度