I was working on a project recently (http://www.youtube.com/watch?v=oy5r8Lsm-y0) and the aim was to publish sensor data coming from an arduino on a user’s facebook wall. I found this tutorial http://blog.theunical.com/facebook-integration/5-steps-to-publish-on-a-facebook-wall-using-php/, but the solution described is not based on Facebook’s Graph API, hence will be deprecated soon.

Here is how I did it with the Graph API…

1) Register a Facebook application and get the App ID and App Secret

2) Ask the user for permission to publish posts on his wall
(see http://developers.facebook.com/docs/authentication/#authenticating-users-in-a-web-application)

Your Facebook App ID is your client_id and your Facebook application secret is your client_secret.


use the scope argument for extended permissions (i.e. offline_access,
publish_stream), you need those in order to post messages on a user’s
wall (see http://developers.facebook.com/docs/authentication/#requesting-extended-permissions)

3) You will be redirected to the specified redirect_url. Copy verification string in the ‘code’ argument from the redirect URL, and paste it into this URL to get (permanent) Access Token:

4) Browser returns Access Token. Use Access Token and Graph API functions to post messages
to user’s wall

…find examples of Graph API post functions here http://developers.facebook.com/docs/reference/api/post, e.g.

curl -F ‘access_token=ACCESS_TOKEN’ \
-F ‘message=Hello World. I like this new API.’ \
-F ‘link=http://www.example.com/article.html’ \
-F ‘picture=http://www.example.com/article-thumbnail.jpg’ \
-F ‘name=Article Title’ \
-F ‘caption=Caption for the link’ \
-F ‘description=Longer description of the link’ \
-F ‘actions={”name”: “View on Zombo”, “link”: “http://www.zombo.com”}’ \
-F ‘privacy={”value”: “ALL_FRIENDS”}’ \
-F ‘targeting= {”countries”:”US”,”regions”:”6,53″,”locales”:”6″}’ \

Further steps…

This solution works, but it still involves manual steps to get a users access token. It would be good to automate this procedure through a server side script. I’m about to get started on this in PHP.


One thought on “How to publish on a Facebook wall using Graph API / PHP

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s