facebook reveals status api – how to use it?

today facebook revealed their new api to update user’s status, and i am quite certain that it will play a vital role in the massive “status” market that is controlled by twitter. lets see how we can update status of any users of your application using this new API called “status_set()”. first thing is to update your facebook client library from this link to make thie api available to your application. and oh, one more thing to note which is very important infact. your users must allow extended permissions for “status_update” before you can do it.

here is the code. first it asks for user’s permission to update his/her status directly from this application. if user grants the permission – we will display a form to our user. then the rest is just hitting the submitting button with new status


<?php
include_once("config.php");
if (!$facebook->api_client->users_hasAppPermission("status_update")){
echo '<fb:prompt-permission perms="status_update" next_fbjs="greet()">Let us update your status from this application</fb:prompt-permission>';
$visibility = "none";
}
else
$visibility = "block";

if(isset($_POST['status']))
{
    $facebook->api_client->users_setStatus($_POST['status']);
    echo "<p>Your status has been updated</p>";
}
?>
<div id="statusdiv" style="display:<?=$visibility;?>;">
    <form method="POST">
        Please update your status:<br/>
        <input type="text" name="status" /> <br/>
        <input type="submit" value="change status" />
    </form>
</div>

<script>
function greet()
{
    var session = "<?=$facebook->api_client->session_key;?>";
    document.getElementById("statusdiv").setStyle("display","block");
    new Dialog().showMessage("Info","Thank you for granting us this permission! Now you can update your facebook status directly from here.");
}

</script>

here is the sequence

screenshot 1: default view, before granting permission
picture-81

screenshot 2: permission dialogue, asking for the authorization
picture-91

screenshot 3: status update form
picture-101

screenshot 4: confirmation
picture-121

so this is it! pretty easy, eh?

Share and Enjoy:
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google
  • blinkbits
  • BlinkList
  • Blogosphere News
  • description
  • E-mail this story to a friend!
  • Furl
  • Gwar
  • LinkedIn
  • Ma.gnolia
  • MySpace
  • Ping.fm
  • Reddit
  • Slashdot
  • Spurl
  • StumbleUpon
  • TwitThis
  • Upnews

65 Responses to “facebook reveals status api – how to use it?”

  1. abhay  on February 22nd, 2010

    Nice article ..

    Can we update status which should be visible to selected friends not to all friends ?

  2. Maquido  on April 3rd, 2010

    All works until…

    Screenshot 2: permission dialogue, asking for the authorization

    Who has the code working?

    Please post an update… thanks

  3. jamescastaneros  on April 13th, 2010

    where can i get the code for config.php?

  4. Rakhmat Ari Wibowo  on April 21st, 2010

    I’ve got this message:
    “Warning: include_once(config.php) [function.include-once]: failed to open stream: No such file or directory in /home/mysite/public_html/facebookapp/app/index.php on line 2″

    How to solve this problem?
    Thanks

  5. Arjun Roy  on May 5th, 2010

    IMAGES

  6. Hussain Ahmed  on May 5th, 2010

    My Image.

  7. Hussain Ahmed  on May 5th, 2010

    Video

  8. Irfan Suleman  on May 11th, 2010

    very nice

  9. raj  on June 10th, 2010

    what is the config.php how to get this ?

  10. youtobest.net  on July 14th, 2010

    You give the source links are dead. curl is more beautiful than we could connect with.

Leave a Reply