2016-11-29 15:24 浏览 70

Facebook使用PHP API发布到页面页面?

I am trying to set up a script to automatically post a message to a Facebook page I am admin of. I have the code below but currently, instead of posting to the page's wall as the page admin, the post is going to the "visitor posts" section of the page from my personal account. Any ideas on how I can resolve this?


$fb = new Facebook\Facebook([
  'app_id' => 'myappid',
  'app_secret' => 'myappsecret',
  'default_graph_version' => 'v2.5',

$pageID = 'mypageid';
$accessToken = 'myaccesstoken';

try {
  $publish = $fb->post('/' . $pageID . '/feed', 
       'access_token' => $accessToken,
       'message' => $status,
       'to' => $pageID
} catch(Facebook\Exceptions\FacebookResponseException $e) {
  // When Graph returns an error
  echo 'Graph returned an error: ' . $e->getMessage();
} catch(Facebook\Exceptions\FacebookSDKException $e) {
  // When validation fails or other local issues
  echo 'Facebook SDK returned an error: ' . $e->getMessage();
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

1条回答 默认 最新

  • 已采纳
    douke6027 douke6027 2016-11-29 15:34

    You need to use the page's access token, not your personal one.

    Using your personal access token, call /me/accounts. It'll give you a list of pages you're an administrator of, and access tokens for each one.

    点赞 评论 复制链接分享