Posting To Your Facebook Feed as Page, not User
You want to post to your Facebook page’s feed, from an app, and have it appear as the page owner/admin, not as an individual, right? It used to be one way, now it’s another.
1- Get permissions with “manage feed” between the app, the user, and the page. Let’s call this access_token1.
2- Using that access token, query the graph “/accounts” connection, and match on page_id. Once you get that, grab the access token, yes, it’s another one. Let’s call that access_token2.
3- Post to the feed using the 2nd access token, only. Don’t need to pass actor_id or anything.
Code sample, which starts with the original access-token. This token used the permissions “manage_pages”
$facebook = initFacebook();
if($access_token1){
$accounts = $facebook->api('/accounts?access_token='.$access_token1);
foreach($accounts as $account){
if($account['id'] == $your_page_id){
$access_token2 = $account['access_token'];
break;
}
}
$args['access_token'] = $access_token2;
$args['name'] = 'test post';
$args['description'] = 'Test Description';
$responseId = $facebook->api($your_page_id.'/feed', 'post', $args);
}
No error handling, but you get the idea.
You used to use “actor_id”, then there was some rule about not posting “relevant content,” and perhaps this is the latest effort to control that. I also saw a bad link in the documentation to an accounts page without access_tokens, which was very misleading. Please comment if you have any contribution, improvements, etc.
Helpful links:
- Buzogány László ‘s comment on the API Reference page, very useful code sample
- Stefan & my thread on this issue long, and wandering, but we got there eventually.
- the FBJS stream.publish page
- the stream attachments documentation
- engelsols’ comment in the Forum on this thread
- the API documentation here – http://developers.facebook.com/docs/api#auth – isn’t wrong per se, now that I understand what they’re talking about. It’s just vague, and doesn’t include code samples.
cateogories: Uncategorized
