Posting content on an user's Facebook wall is very easy using the PHP-SDK. However on various situations you might be required to do a wall post to an user without making use of the PHP-SDK and by directly accessing the Graph API URL. We will be using a PHP utility called CURL in order to perform this programmatic Post to a Facebook Wall using the Graph API but Without using the PHP-SDK.
If you want to Post to a Facebook User's wall using the standard method (Graph API + PHP-SDK) then see this tutorial.
This guide has been written after referring to these following resources from the Facebook Documentation.
Using the Graph API, any Facebook user's Wall feed may be accessed by using this URL:
So, if you want to post something on the wall of an user whose Facebook ID is 12345678, then the URL changes to
And if you want to post to the Wall of the current logged in user then you simply replace the USER_ID with me so that the URL becomes:
Now that you know which URL to call in order to do the posting, let us come to the code snippet which will do the actual posting on the Facebook wall of a user via the Graph API without using the PHP-SDK. One thing you must remember that passing an access token is of utmost importance without which any Graph API method would fail, except for the ones which make their info available publicly.
Please not that in order to post something on any user's Facebook wall, you will need to ask the user for the publish_stream extended permission. Here is the code snippet:
How to find out if the Wall Post was successful?
The function in the code above returns a value which contains the Facebook ID of the wall post you just made in the following format:
So, if the logged in user's Facebook id is 12345678 and the id of the wall post is 987654321, then the function's return value would be:
So, in order to find out if the wall post was successful, you can search for the logged-in user's Facebook ID in the return value using the PHP function strpos(). A TRUE value would imply that the wall post was successful.
If you are facing any problem with the implementation do write to me at: firstname.lastname@example.org. You can also hire me for developing Facebook applications for you.
Related Posts by Tags: curl, Facebook, graph, graph api, php-sdk, post, programmatically, user, wall