Site icon Web Niraj

Facebook API: Posting As A Page

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:

See the gist on github.

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:

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

See the gist on github.

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:

See the gist on github.

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.

See the gist on github.

Exit mobile version