Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
583 views
in Technique[技术] by (71.8m points)

facebook graph api - How to post to Facebookpage as admin via API (Php SDK)?

I know how to make a post to a Facebook page via the API using PHP SDK, that is done like this:

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

Where xxxxxxxxxxx is page 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?

Thanks you for your time!

ANSWER (for lazy people):

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>

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' => ''));
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

Long story short, you need the manage_pages extended permission.

And btw, have you checked this first ?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...