duanjian5059 2016-11-29 15:24
浏览 72
已采纳

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?

require_once('Facebook/autoload.php');

$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', 
     array(
       'access_token' => $accessToken,
       'message' => $status,
       'to' => $pageID
       )
   );
} catch(Facebook\Exceptions\FacebookResponseException $e) {
  // When Graph returns an error
  echo 'Graph returned an error: ' . $e->getMessage();
  exit;
} catch(Facebook\Exceptions\FacebookSDKException $e) {
  // When validation fails or other local issues
  echo 'Facebook SDK returned an error: ' . $e->getMessage();
  exit;
}
  • 写回答

1条回答 默认 最新

  • 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.

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

报告相同问题?

悬赏问题

  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作