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