Posting To Your Facebook Feed as Page, not User

Anna • January 25, 2011 • Comments View Comments

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.

Category: Facebook, Tech, Techniques

About the Author

I'm a developer with Momentus Media. I've done the gamut of OLAP DB modeling to iPhone development and Ruby on Rails. Now, I'm in the fast lane of rapid, viral app development on Facebook.

View Author Profile
  • http://www.ericarenson.com/ Eric

    Thanks for posting this! It helped get me on the right track, even though for whatever reason the /accounts API call wasn’t working for me. I had to visit the full Graph API url in the browser to get the list of pages, but I was so excited to get the page access_token I didn’t think too much about why!

  • Dihaz

    I am getting this error :(
    GraphMethodException: Unsupported get request.

  • http://www.banane.com banane

    Glad it worked! Note: you have to use the first access_token to get the second (accounts) access_token.

  • http://www.banane.com banane

    try printing out your request, and copy and paste that into a browser url, and you’ll get a more explicit response (or use catch-FacebookApiException $e) and print out the $e. Also, see note below- you need an access_token to ge the second access_token.

blog comments powered by Disqus