Posting to Facebook fan page wall as an admin using Facebook API

August 17, 2010
By Bogomil Shopov
13 Comments
Post Image

I know, I know. This is a blog about Open Technologies and Open Web and I am writing about Facebook. Shame on me :)
It’s a little bit tricky and I’ve lost 3 hours to resolve it and that’s the reason to post it here

Here is the solution.:

1. If you are reading this, probably you have Application setup-ed already in Facebook;
2. Add your application to your Page;
3. Run this link in your Browser. Please replace ~URL~ with your connect URL (Facebook Application dialog) and ~APPID~ with your application ID

https://graph.facebook.com/oauth/authorize?type=user_agent&client_id=~APPID~&redirect_uri=~URL~&scope=publish_stream,offline_access,manage_pages

4. This URL will return to you a URL parameter access_token.
5. Save the token somewhere;
6. Load This URL. Replace ~TOKEN~ with the token received from Facebook at point 4.;

https://graph.facebook.com/me/accounts?access_token=~TOKEN~

7. As a result you will get the json with all your pages and all access tokens. Save them somewhere;

{
         "name": "Electronic Frontier Bulgaria",
         "category": "Websites",
         "id": "29469045921",
         "access_token": "some secret string."
      },

8. Use FB js SDK to update your page. Replace ~PAGE_AUTH~ with access_token from the previous point. (some secret string)

var wallPost = {
    access_token: "~PAGE_AUTH~",
    message: 'Talkweb.eu is the best :)'
};

FB.api('/me/feed', 'post', wallPost, function(response) {
    if (!response || response.error) {
        alert('Error occurred');
    } else {
        alert('Success!');
    }
});

9. Check the page to see the result;
10. Bye me a beer or hire me :)

If you have any questions, please let me know!

Bogomil Shopov

I care about privacy, ethical design, and freedom in many aspects. I spend 20+ years working as a web developer and architect, analyst, manager, and product owner/manager in different environments, several countries, and multiple software industries like Healthcare and Hospitality. I wore many hats, and I use the knowledge gathered to optimize the flow of value across complex systems.

13 Comments

  • Annalivia

    September 23, 2010 at 7:44 pm

    Matt Barton has posted some sample code here to automate this using the Facebook PHP SDK – it might help
    :
    http://bugs.developers.facebook.net/show_bug.cgi?id=10005#c139

    Reply
  • Abe

    November 16, 2010 at 7:52 pm

    can you explain what you mean by, “connect URL (Facebook Application dialog) ” in step 3? I am having trouble getting past this point…

    Reply
  • Abe

    November 16, 2010 at 7:59 pm

    Nevermind, I figured that part out. Is there a way to do steps 6/7 in code?

    Reply
  • ahmad

    March 28, 2011 at 12:10 pm

    good article. i have been searching for a solution since 4 hours

    Reply
  • Mr.Mike

    May 21, 2011 at 1:37 am

    This is the best explanation I’ve found so far and got me up and running in minutes. Thanks, Bogo!

    Reply
  • Martin

    May 23, 2011 at 3:16 pm

    thx for sharing this, – short and effective !!!! ;)

    Reply
  • Vini

    July 23, 2011 at 11:24 pm

    Thank you for sharing this information since Facebook API is really vague. It worked for my application for around a week, and suddenly it stopped working 2 days ago. Every time i try to publish on my page’s wall, it posts that on my own wall. I don’t know, does it have to do with the access token?

    Plz let me kno

    Reply
  • Marco

    October 20, 2011 at 5:25 pm

    Hi,

    I’ve followed all the steps and now my APP is posting on my PAGE WALL.

    BUT

    If I check the post it says something like “2 hours ago via APP_NAME”

    So the post has been posted VIA THE APP and NOT AS if I manually use the form …

    So am I doing wrong?

    Can you help me, please?

    Thanks!

    Marco

    Reply
    • Bogo

      October 21, 2011 at 2:54 pm

      Have no idea. this tutorial is almost 1 y old and Facebook may change something again to their API

      Reply
  • Sokool84

    October 23, 2012 at 3:40 pm

    You are My Master :)) Thank You for Solution.

    Reply
  • soundhar

    February 10, 2013 at 5:58 pm

    Hey using this code can i post to the facebook page without app details? I want to post to facebook page from php like admin post

    Reply
  • Joseph

    April 12, 2013 at 1:45 pm

    How to post to my page as the page, not me?

    Reply
  • Indrajeet

    January 31, 2014 at 2:34 pm

    Thanks alot…..It worked out fine.

    Reply

Leave a reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.