Facebook Graph API to Post Status Update
Wall Script
Wall Script
Thursday, March 31, 2011

Facebook Graph API to Post Status Update

Few days back I had posted an article about Facebook Graph API connection and explained how to request facebook access token and reading home timeline feed. This post is sequel how to update Facebook wall status from third party site with existing access token in "users" table. Try demo at labs.9lessons.info

Facebook Graph API Status Message Update

Live Demo


Previous Post: Facebook Graph API Connect with PHP and Jquery

Facebook Status Message Update

Update.php
Contains HTML and PHP code. Getting facebook_access_token and facebook_id values from users table where uid=$user_session_id.
<?php
include('db.php');
if($_SERVER["REQUEST_METHOD"] == "POST")
{
$status=$_POST['status'];
$sql=mysql_query("select facebook_id,facebook_access_token from users where username='$user_session'");
$row=mysql_fetch_array($sql);
$facebook_id=$row['facebook_id'];
$facebook_access_token=$row['facebook_access_token'];
//Facebook Wall Update
params = array('access_token'=>$facebook_access_token, 'message'=>$status);
$url = "https://graph.facebook.com/$facebook_id/feed";
$ch = curl_init();
curl_setopt_array($ch, array(
CURLOPT_URL => $url,
CURLOPT_POSTFIELDS => $params,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_VERBOSE => true
));
$result = curl_exec($ch);
// End
}
?>
//HTML
<form method="post" action="">
<textarea name="status"></textarea>
<input type="submit" value=" Update "/>
</form&gt;
web notification

39 comments:

  1. It's like I want to know something and BOOM! You make a tutorial. Thanks! :D

    ReplyDelete
  2. Hi
    really a helpful post.
    I have a query.. In this code which variable should contain the status string.

    ReplyDelete
  3. Without using curl:
    include "facebook.php";
    if ($_POST['boton'] == "Public" ){
    $estado=$_POST['publicar'];
    $propiedades=array('message' => $estado);
    $facebook->api('/me/feed','post',$propiedades);
    }
    o api('/facebook_id/feed'

    ReplyDelete
  4. @UrbaN77
    Facebook Official PHP SDK you mentioned also uses cURL to interact with their API.

    @Tamada
    There is a small syntax glitch in the code you provided for update.php at around line 12.

    ReplyDelete
  5. Facebook has become a great device for making stats and database...

    ReplyDelete
  6. very usefull and inportante post...thank's for sharing

    ReplyDelete
  7. works great!! thx. how do you add an icon before for the name of the website

    ReplyDelete
  8. please donate money to this guy, he is so helpful

    ReplyDelete
  9. thank you brilliant exactly what i was looking for!!!

    ReplyDelete
  10. Hi i am abhishek...........
    my issue is

    Notice: Undefined variable: user_session in C:\xampp\htdocs\FBStatus\home.php on line 3
    // Javascript Code------------------------------------- // HTML Code---------------------------------------------
    Notice: Undefined variable: facebook_uid in C:\xampp\htdocs\FBStatus\home.php on line 40


    please help meee................

    ReplyDelete
  11. Which variable contains the text - via "9lessons lab" ?

    ReplyDelete
  12. Could u give the script plzz... ?

    ReplyDelete
  13. another thing, how can you impersonate the Page instead of using your current user ????

    ReplyDelete
  14. Can you make the this things. :P
    the user or someone who is looking for comment can simply find it by choosing the time and date and so on. or name or places or any code:P hope you understand my english. thnx.

    ReplyDelete
  15. Ok so im a dummy, the users table? im guessing it contains the facebook id of the user right? is that something i have to get off the user? how does this work?

    I want to place it below photos for commenting on my clients site

    ReplyDelete
  16. Can you help me when I test it Error:

    Fatal error: Uncaught exception 'Exception' with message 'Facebook needs the CURL PHP extension.' in C:\wamp\www\Facebook_API\facebook.php:20 Stack trace: #0 C:\wamp\www\Facebook_API\test.php(3): include() #1 {main} thrown in C:\wamp\www\Facebook_API\facebook.php on line 20

    ReplyDelete
  17. i am getting following error.
    {"error":{"message":"Error validating access token: Session has expired at unix time 1321603200. The current unix time is 1321868555.","type":"OAuthException"}}

    ReplyDelete
  18. Very nice and efficient blog..

    ReplyDelete
  19. i get the post id, but i don't see the post on my wall .. where is the problem ?

    ReplyDelete
  20. hi will this still work for the new API? also, do you have a tutorial wherein the api can post status together with an image? something like this:

    http://i.imgur.com/Edtos.png

    sorry for the confusing messages of the image. thanks in advance!

    ReplyDelete
  21. please tell me about tha db.php file

    ReplyDelete
  22. nice post! but can u tell us how to post on the wall using API?

    ReplyDelete
  23. pls upload the update.php here bcos i cant copy the code.tanx

    ReplyDelete
  24. params = array('access_token'=>$facebook_access_token,

    fix it with

    $params = array('access_token'=>$facebook_access_token,


    :P nice tutorial !!

    ReplyDelete
  25. Thank's a lot for this tutorial!

    ReplyDelete
  26. When i am trying to use the code i am getting the following error "Malformed access token"

    ReplyDelete
  27. Same error :{"error":{"message":"Malformed access token

    ReplyDelete
  28. where can i find db.php file ? plz help

    ReplyDelete
  29. Code no longer posts to facebook i think you need permission to the app which this code does not make the app do.

    ReplyDelete
  30. Where can I find db.php?

    ReplyDelete
  31. That's amazing web blog and thanks for sharing..

    ReplyDelete

mailxengine Youtueb channel
Make in India
X