Facebook使用PHP API发布到页面页面? [英] Facebook posting to page as page using PHP API?

查看:306
本文介绍了Facebook使用PHP API发布到页面页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试设置一个脚本来自动发布一个信息到Facebook页面,我是管理员。我有下面的代码,但目前,而不是作为页面管理员发布到页面的墙上,该帖子将从我的个人帐户的页面的访客帖子部分。关于我如何解决这个问题的任何想法?

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;
}


推荐答案

您需要使用该页面访问令牌,而不是您的个人信息。

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

使用您的个人访问令牌,调用 / me / accounts 。它将为您提供一个您是管理员的页面列表,并为每个页面访问令牌。

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.

这篇关于Facebook使用PHP API发布到页面页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆