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

7

我知道如何使用PHP SDK通过API向Facebook页面发布帖子,方法如下:

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

其中 xxxxxxxxxxx 为页面 ID ;)

但是这样做,我会以我的名字 Jamie 发布到该页面,而不是作为页面本身(管理员)发布。
那么,如何以管理员/页面的身份发布,而不是以自己的身份发布呢?

感谢您的时间!

答案(懒人专用):

首先,您需要确保可以管理用户页面,例如:

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

现在,当您获得用户访问权限后,每个页面用户都会获得一个特殊的令牌。
PHP SDK 示例:

//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' => ''));
1个回答

6

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接