如何通过 API (Php SDK) 以管理员身份发布到 Facebookpage?

2021-12-20 00:00:00 php facebook facebook-graph-api

我知道如何使用 PHP SDK 通过 API 在 Facebook 页面上发帖,具体操作如下:

$facebook->api('/xxxxxxxxxxx/feed', 'post', array('message'=> 'Hello world!', 'cb' => ''));

其中 xxxxxxxxxxx 是页面 ID ;)

但这样做时,我以我自己的身份发布到该页面,杰米,而不是页面本身(管理员).
那么我如何以管理员/页面的身份而不是我自己的身份发帖?

But doing that, I post to that page as me, Jamie, and not as the Page itself (admin).
So how do I post as Admin/Page instead of myself?

感谢您的时间!

答案(针对懒人):

首先,您需要确保您有权管理用户的页面,例如:

First of all you need to make sure you have access to manage pages for user, ex:

<fb:login-button autologoutlink="true" perms="manage_pages"></fb:login-button>

现在,一旦您获得用户有权访问的每个页面,您还将获得一个特殊的令牌.
PHP SDK 示例:

Now you also gets a special token for every page user have access to once you get them.
PHP SDK Example:

//Get pages user id admin for
$fb_accounts = $facebook->api('/me/accounts');
//$fb_accounts is now an array 
//holding all data on the pages user is admin for, 
//we are interested in access_token 

//We save the token for one of the pages into a variable 
$access_token = $fb_accounts['data'][0]['access_token'];

//We can now update a Page as Admin
$facebook->api('/PAGE_ID/feed', 'post', array('message'=> 'Hello!', 'access_token' => $access_token, 'cb' => ''));

推荐答案

查看关于您的问题的说明:http://developers.facebook.com/docs/api > 授权 > 页面模拟.

Check out this note regarding your question: http://developers.facebook.com/docs/api > Authorization > Page impersonation.

长话短说,您需要 manage_pages 扩展权限.

Long story short, you need the manage_pages extended permission.

顺便说一句,你有没有检查这个 首先?

And btw, have you checked this first ?

相关文章