Web Niraj
  • Facebook
  • Flickr
  • Github
  • Linkedin
  • Twitter
  • YouTube
Online portfolio, code examples and developer blog
  • About
  • Contact
  • Portfolio
  • WordPress
Search the site...
  • Home
  • Blog
  • Facebook API: Posting As A Page

Facebook API: Posting As A Page

22

The Facebook API lets you post to Pages you own automatically – either as real-time updates or in the case that you want to schedule posts. It could even be because you want your colleagues to post updates to a page, without giving them direct access. Here’s how to achieve posting to a page…

UPDATE:  See this tutorial for Facebook PHP SDK 4.0.x / Graph API v2.x version.


First off, you need to add the manage_pages and publish_stream permissions to your app. This will let the application access the pages you own, and give the application permission to post to these pages. Note that this permission will give an application access to all the pages you own – not just the one you want to use.

Next, you need the access_token for the page you want to post to. This can be done by making a simple API call, as follows:

GET https://graph.facebook.com/me/accounts

This will list all the page details as follows:

Note that the response includes details about each page, including name, ID and access_token. Once you have the access_token, posting an update to your page is easy. Simply make another call to the API as follows:

POST https://graph.facebook.com/[page_id]/feed?access_token=[page_access_token]

Along with the API call, you must post at lease one of the following parameters:

  • message – the text for the status update, e.g. “Thanks for helping us reach 1.000 fans”.
  • link – A URL to a website you want to link to
  • picture – URL of an image you want to include in the update
  • name – The name of the link attachment
  • caption – The caption of the link (appears beneath the link name)
  • description – The description of the link (appears beneath the link caption)

For example, if I wanted to post a link to this article, my data would look like:

Once the API call has been made, Facebook will return the post_id for the update, so you can later get information back on it. If no post_id is included, an error message will be returned letting you know what went wrong. The return data will look like:

You can see the created update by copying the ID returned in the call and going to:

https://www.facebook.com/[post_id]

E.g. https://www.facebook.com/01234567890_001122334455667788, if we use the above example. Facebook will turn the above link into something like:

https://www.facebook.com/permalink.php?story_fbid=[post_id]&id=[page_id]

The status update on the page itself will look something like.

A full list of properties to use with the /feed API call can be found on Facebook’s Documentation for Feeds.

If you see a error message like the following when attempting to post to the page, you are missing the publish_stream permission. You won’t be able to publish to the page without this permission. Note that accepting this permission will also give the application access to publish posts to your own timeline.

Facebook, Facebook Graph API, Fan Page, Tutorial

22 comments on “Facebook API: Posting As A Page”

  1. Aman says:
    January 11, 2013 at 3:11 PM

    Thanks very much
    I searched everywhere on the internet about posting on page but nothing found.
    when i came to your post i found the solution after 3 hours of searching.
    Keep posting good tutorials……..

    Reply
  2. Maulik says:
    April 24, 2013 at 6:23 AM

    Thanks for this wonderful tutorial! Saved my life. Can you also help with posting comment to any particular post on my fb page? I tried searching for it but no luck 🙁

    Reply
  3. Elam Parithi says:
    July 28, 2013 at 3:27 AM

    Does this work with Graph API now?? I have been trying for months for now its now working.

    Reply
  4. Hassan says:
    August 12, 2013 at 10:15 PM

    Its posting as a user not as the page .. you should check it again..

    Reply
    • Niraj Shah says:
      August 13, 2013 at 10:30 AM

      Make sure you are following the steps correctly. If you don’t have a valid page access_token, you won’t be able to post as the page.

      Reply
  5. Hassan says:
    August 15, 2013 at 7:13 PM

    I did it and told you 🙂 I’ve get the access token from the given method 🙂

    Reply
  6. KP says:
    August 20, 2013 at 5:12 PM

    Tried your post. Used the page access token but still is posting as a user and not as a page….Any ideas?

    Reply
    • Niraj Shah says:
      August 20, 2013 at 10:25 PM

      Email me your code and I can take a look. Haven’t encountered this issue myself, but it could be around the page’s permissions or the app permissions you’ve asked for…

      Reply
  7. Uknown says:
    September 6, 2013 at 1:45 PM

    Niraj , when I post link using graph , it post a smaller thumbnail , but when I post directly , a big thumbnail is appeared, it effects the reach of users , can you kindly tell me any solution for this ?
    will be waiting for your kind reply .

    Reply
  8. MiChiamoPeiPei (@mushroompp) says:
    October 16, 2013 at 10:33 PM

    Love this post!!!!! <3<3<3<3<3<3<3

    Reply
  9. gaulucky92 says:
    April 16, 2014 at 11:05 AM

    Hello, I currently followed your instructions and encountered a problem here:
    – If I only provide the “message”, no “link” and other link-parameters => The post will be posted as the page identity.
    – If I also provide the “link”, everything runs nicely except one thing that the author name is my real profile, not the page identity!

    Both cases have the same access_token taken from “/me/accounts”.

    I’ve copied the api call url and ran it with Graph API Explorer and got the same results.

    I’ve been searching for a whole day but still find no resolution!

    I guess there are problems with the Facebook Graph API?

    Reply
    • Niraj Shah says:
      April 17, 2014 at 2:13 PM

      Sounds like a bug to me. Have you tried checking the Facebook Bug site for any matching reports?

      Reply
    • mattheuspirovaniMattheus says:
      April 24, 2014 at 1:49 PM

      Hey friend, same behavior here!! Did you find the solution?

      Reply
  10. Facebook API: Posting As A Page using Graph API v2.x and PHP SDK 4.0.x | Web Niraj says:
    August 23, 2014 at 2:14 PM

    […] API.  With the release of Graph API v2.x and the new Facebook PHP SDK v4.0.x, I’m updating my old tutorial to show how to achieve the same functionality using the newer Graph API and PHP […]

    Reply
  11. Luca Pandolfo says:
    March 2, 2015 at 4:31 PM

    I tried it but I have this message

    Fatal error: Uncaught OAuthException: (#200) The user hasn’t authorized the application to perform this action thrown in /web/htdocs/www.finsicilia.it/home/sdk/fb/src/base_facebook.php on line 1325

    Reply
    • Niraj Shah says:
      March 3, 2015 at 10:00 AM

      Are you asking for the correct permissions to post to the user’s page? You need manage_pages permission to access the pages, and the publish_actions permission to post content. It sounds like you're missing one of those.

      Reply
  12. Umer Spall says:
    August 11, 2015 at 5:12 PM

    i am trying to post on facebook page via facebook app.

    Instead of page time , post is shown on left side of the facbook page.
    what can be the issue.

    Although same code/same post is working fine for facebook group

    Reply
    • Niraj Shah says:
      August 14, 2015 at 8:00 PM

      Are you using your page access_token to post to the Page? If not, you’re posting as the user, so the page is showing this under the “Posts by Users” section.

      Reply
  13. Shirish says:
    September 5, 2015 at 8:59 AM

    Hello , I have added publish_stream, manage_pages permissions but still I am getting “Fatal error: Uncaught OAuthException: (#200) The user hasn’t authorized the application” issue.

    Reply
    • Niraj Shah says:
      September 10, 2015 at 10:35 AM

      Use the publish_actions permission instead. publish_stream is depreciated.

      Reply
  14. dodong jan jan says:
    October 28, 2015 at 7:06 AM

    First of All, I would like to thank you for your post. A great help for me. Anyway,I have a newbie question. How to remove the author details?

    Reply
    • Niraj Shah says:
      November 3, 2015 at 9:46 AM

      The author details cannot be removed. But note that these are only visible to other Admin users. The end-user won’t see the author details.

      Reply

Leave a ReplyCancel reply

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

StackExchange / StackOverflow

profile for Niraj Shah on Stack Exchange, a network of free, community-driven Q&A sites

Support Me

Buy Me a Coffee

PSN Profile

Tags

ACL Amazon Web Services Android Android 4.4 KitKat Android 5.0 Lollipop Apache Backup Bash Bug Command Line Cordova cPanel / WHM Facebook Facebook Graph API Facebook PHP SDK 4.0 Facebook Social Plugins Fan Page Flash Geolocation Google Nexus 5 Hacking HTML5 Input Sanitization iOS JavaScript jQuery Laravel 5 Laravel 5.2 Linux Mac OS NodeJS Parse PDF PHP Plugin Portfolio Review Security Server SSH SSL Sysadmin Tutorial WordPress WordPress Plugins
© 2011-2025 Niraj Shah
  • Blog
  • Portfolio
  • WordPress
  • About Me
  • Contact Me
  • Privacy Policy
Privacy & Cookies: This site uses cookies. By continuing to use this website, you agree to their use.
To find out more, including how to control cookies, see here: Privacy Policy