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
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:
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:
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/01234567890_001122334455667788, if we use the above example. Facebook will turn the above link into something like:
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.