Site icon Web Niraj

Facebook API: Posting a Status Update

The Facebook API lets you post status updates (message, links, photos etc) to your timeline via the API. This is handy if you want to have automatic sharing in your application (assuming users have consented to it) to post uploaded photos, links etc. The concept is easier than Posting to a Page, which I’ve covered previously.

First off, you need to add the publish_stream permission to your app to allow automatic posting of text, links, or photos to the timeline. This is known as an ‘additional permission’ for Facebook Applications, which the user has the option of skipping when adding your application.

In order to post a status update to the timeline, we must make a POST call to the /{user_id}/feed API endpoint. For the logged in user, the endpoint we need is below. At the minimum, we need to include the message parameter and access_token.

See the gist on github.

If successful, Facebook will return an ID for the post, which is made up of your User ID and the ID for the post.

See the gist on github.

If you want to post images, links etc, you can include additional parameters in your API call. The following are just a few parameters you can use:

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

See the gist on github.

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

See the gist on github.

The status update 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.

Exit mobile version