Hi,
This post is again a continuation of my previous posts related to Facebook Graph API. This one will sum up all the earlier post with a new functionality of posting to your own or friends wall. In this also I will be using the $facebook->api() to post in wall. Click here to download the entire source code.
My current page looks like:
In the above I have a form for updating my Facebook status. When I click the image of my friends a popup comes up and lets me post to that fiends wall as follows:
Code and explanation:
First I am creating the following form for submitting the post:
<form method="post" action="">
<input type="hidden" name="user" value="FACEBOOK_USER_ID">
<textarea name="status" style="border:1px solid #ccc;width:289px" rows="4"></textarea><br/><br/>
<input type="submit" value="Post in Wall">
</form>
Now when the form is submitted, I am using the $facebook->api() function to post in wall as:
if (isset($_POST['status']))
{
try {
$statusUpdate = $facebook->api('/'.$_POST['user'].'/feed', 'post', array('message'=> $_POST['status'], 'cb' => ''));
} catch (FacebookApiException $e) {
echo "<div style='color:red'>Error!! Status update failed.</div>";
}
if(!empty($statusUpdate)){
echo "<div style='color:green'>Congratulations!! Your facebook status has been successfully udpated.</div>";
}
}
}
In the above:
$facebook->api('/'.$_POST['user'].'/feed', 'post', array('message'=> $_POST['status'], 'cb' => ''));
is the syntax for sending post, where $_POST['user'] is the Facebook user ID and $_POST['status'] is the status message.
Download: fb_wall_post.zip
After downloading the source code, you just need to change the API key and secret key, which you can generate for your website from https://developers.facebook.com/setup/
Cheers!!!
I like this, but it doesn't work for me :(
ReplyDeleteWhen i click, post button, go the screen http 500 error...
what mistakes?
thanks the answer!
Are you using correct facebook api keys? because there are all working codes. I will still double check and get back to you, in case facebook has changed any of its API's
ReplyDeletethanks for the reply, it still failed, but keep trying ;)
ReplyDeleteeverything is fine in principle
Fatal error: Call to undefined method Facebook::getSession()
ReplyDeletehelp me please for solutions
Can We Make It Like
ReplyDeleteIt Will Post On All Friends Wall In Just One Go ?
good work dear....
ReplyDeletethanks u so much....
its working....
but not working for one person.
DeleteThanks for posting It's working fin..
ReplyDeleteFacebook.FacebookOAuthException: (OAuthException - #200) (#200) Feed story publishing to other users is disabled for this application- i m getting above error
ReplyDeleteHello,
ReplyDeleteI've got the same message :
"Feed story publishing to other users is disabled for this application- i m getting above error"
in source code line 4 gives an error.. i thnk in session
ReplyDeleteHello,
ReplyDeletethis code is not working fine for me. earlier it was giving this erro messages:
Notice: Undefined variable: uid in D:\wamp\www\testpages\fb_wall_post\example.php on line 21
Fatal error: Uncaught CurlException: 60: SSL certificate problem, verify that the CA cert is OK. Details: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed thrown in D:\wamp\www\testpages\fb_wall_post\src\facebook.php on line 640
Then i comment these lines but still its not working properly.
http://my.xportsoft.com/fb_wall_post/example.php
pls check this.
hi there can i post on friend wall
ReplyDelete