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
![]()
screenshot 2: permission dialogue, asking for the authorization

screenshot 3: status update form

so this is it! pretty easy, eh?
65 Responses to “facebook reveals status api – how to use it?”
Leave a Reply




























swordfish on February 7th, 2009
nice! we’ll see lotz of applications twittering around.
thanks for sharing Hasin bhai!
Arafat Rahman on February 7th, 2009
Thanks for the article.
by the way, you may use lightbox plugin for the images into your posts.
bijon on February 7th, 2009
just one small type mistake in the code :
if(!emptyempty($_POST['status']))
Also to update the status we may be user another function status_set : $facebook->api_client->status_set($_POST['status']);
here is the link: http://wiki.developers.facebook.com/index.php/Status.set
again by this articles learn about the latest api of the fb .
Hasin Hayder on February 8th, 2009
thanks @bijon – emptyempty is now corrected.
and users_setStatus() is the alias of Status.set in facebook PHP client library
murshed ahmmad khan on February 8th, 2009
thanks hasin bhai for the post. i am planning to build an application on it
.
rc29 on February 9th, 2009
Nice article, keep on !!
ranacse05 on February 10th, 2009
I did this about 3 months ago by editing the lib file
and now the change the lib . Its nice .
rc29 on February 10th, 2009
Hi, how do you indicate the ID of the user to update ? Thanks a lot !
Hasin Hayder on February 10th, 2009
@rc29 when you call it, it will update the status of currently logged in user. but if you want to do it offline – you must have his or her session key
and then
[sourcecode language='php']
$fb = new Facebook($api, $secret);
$fb->api_client->user = $user;
$fb->api_client->session_key = $session;
//now u r simulated as that particular user
[/sourcecode]
rc29 on February 10th, 2009
yes, i did that, i was about to post this answer when i saw your message! Thanks !
ML on February 11th, 2009
Ok, I am a goof at programming, so sorry if this is a stupid question.
I would like to implement this in a Worpress Plugin, so that my visitors can update their status from within my blog. Kinda like what CNN did at the Obama inaguration. I am already using the Facebook Connect Plugin from Sociable, som many of my readers have already logged in with their Facebook ID’s. Don’t know if that makes it easier?
How do I make the code into a Wordpress-plugin that I can insert as a widget or somethin like that?
Hope somebody can help me with this!
LK on February 12th, 2009
Useful!
Perhaps this is more of a facebook question, but is it possible to add pretty urls in status field e.g. example
and it shows up as clickable ‘example’?
Hasin Hayder on February 12th, 2009
@ML
sorry for late replay but stay tuned, we are coming with a standalone solution for that. soon you will find an article focusing on that issue
@LK
mmmm, as far i am concerned, it is not possible! FB doesn’t allow passing any html tag in status text.
ML on February 15th, 2009
@Hasin: Great! Looking forward to it! I would love having a shoutbox in my sidebar, where visitors could shout their status-updates.
Another thing, inspired from a newer article of yours: I would love to be able to notify my Facebook Connect visitors of new comments to posts they already commented on. *drooling*
cesar on February 18th, 2009
Hi y try to use this code that it didnt work to me…. what can I do? SOMEBODY HAD A FUNCTIONALY CODE?
THANKS
pasturepool on March 16th, 2009
when I try to open the page I created I receive this error:
Fatal error: Call to a member function users_hasAppPermission() on a non-object
Michael Soriano on April 4th, 2009
Hi Hasin,
I just want to update users status with random strings but I get a Call to undefined method error: FacebookRestClient::status_set(….
below is my code:
include_once(”facebook-platform/footprints/config.php”);
if (!$facebook->api_client->users_hasAppPermission) {
$facebook->api_client->status_set(’is the Eagle has landed.’,”);
}
Drew on April 15th, 2009
@Hasin from Feb 10th.
Hasin or Anyone,
I would like to update certain status profiles offline after they have allow my application to do so. Hasin posted some code to do if offline but I don’t understand where the session code goes. Can someone please explain?
Thanks
Bill on April 24th, 2009
Is there no way to use status_set() via javascript?
ws on May 13th, 2009
I am not sure about this error can you provide some focus on it.
Fatal error: Uncaught exception ‘FacebookRestClientException’ with message ‘Session key invalid or no longer valid’
I am using the same example above.
Thanks
GC on May 16th, 2009
Apologies – programmer newbie. Once you are given access to a user’s stream, can you pull down historical status updates, e.g: their status updates for the previous month, year etc?
Thanks
Shubhada on May 20th, 2009
Thanks for solution. but here m little bit confused. Please help me.
I have download facebook_platform tar but in this absent the client directory.
can u please tell me where the write example code of the application and also where to copy above code which is take permission of user.
and also please tell me is any changes in index.php of footprint.
Here m confused please tell me in details so we can use this application.
Shubhada on May 21st, 2009
can anybody help me?
Alex Zydlewski on July 6th, 2009
TFZHLO Hi! The post is really interesting! I?ve read your blog and can say it?s a good job.thanks,
Chuck Reyer on July 6th, 2009
Great work ?. Thanks for your ideas.,
Kimpya on July 6th, 2009
Thank you for this site, such as multi information.I! Thank you!,
Jon Bollinger on July 6th, 2009
thanks for you.. nice good document!,
Susanne Lewis on July 6th, 2009
great tips. I enjoyed reading this,
Rosemay Womack on July 6th, 2009
I think its good decision what he did.,
brenda schwartz on July 6th, 2009
Oh hell yeah? no graphical smilies around here.,
Donald Beall on July 6th, 2009
Hi can someone please translate for me thanx,
Meg McQueen on July 6th, 2009
great site. I love online games,
kim chow on July 6th, 2009
Thanks I?ll give that a go!,
joella yungerberg on July 6th, 2009
thanks for you.. nice good document!,
Alberto Torres on July 6th, 2009
Thank you! I liked the article! I love how you write beautifully.,
Tom Pretko on July 6th, 2009
Don?t you think he is a little late for the game?,
Kevin Boutte on July 6th, 2009
what gives you that idea?,
Juegos on August 26th, 2009
Anyone knows how to make a plugin to update facebook? thanks
Niju on September 5th, 2009
I’m newbie to this. Well my requirement is to update status when loading an url. What now happens is it goes to the call back url and all.
Is there any other method or settings to be done for that???
include_once(”config.php”);
// the facebook client library
include_once ‘../php/facebook.php’;
// some basic library functions
include_once ‘lib.php’;
$facebook = new Facebook($api_key, $secret);
$facebook->require_frame();
$user = $facebook->require_login();
$facebook->api_client->users_setStatus($_POST['status']);
aaa on October 6th, 2009
if i get one of the facebook developers then its going to be a real faceboom.
i will break his nose and the nosebreak will genetically manifest itself. still in 2000 years all ancestors will have a slanted nose.
aaa_fan on November 10th, 2009
I completely agree with aaa and will help him in that mission.
shah on November 20th, 2009
hi.. can i hv the config.php pls???
noobie PHP programmer here
tiptonp on December 11th, 2009
@shah there is a link in the article called from this link DL it and the config file is in there.
Priyanka on December 17th, 2009
Awesome Post! Thank you!!!
script to should ask for authorization only once, must save the session and how to make it automatically connect when they got back later?
thecoder on December 19th, 2009
hello,
when i put your code , the tag isn’t rendred , so it is detected as a normal xml tag.
i’v tried to add a connect button, and it’s displayed correctly !
when i click @ connrct button then suddenly the xml tag is rendred correctly !
i’m new on facebook api , can you help me plz . i’m really confused.
regards
sumon on January 4th, 2010
Nice Post Hasin Bhai. Really helpful
SChaput on January 23rd, 2010
I keep getting this error:
Fatal error: Call to a member function users_hasAppPermission() on a non-object in /home1/ihatemyr/public_html/thebook/footprints/index.php on line 6
Can someone explain what i’m doing wrong? I copy the code seen above into the index.php enclosed in the facebook folder i downloaded
rockemon on January 25th, 2010
put this 3 line before
if (!$facebook->api_client->users_hasAppPermission(”status_update”)){
here :
$facebook = new Facebook($api_key, $secret);
$facebook->require_frame();
$user = $facebook->require_login();
seafarerpro on February 5th, 2010
Looks like everything has to go with an app set up within FB. That means there is no way to allow to post status for anyone, with his/her login information on the fly. But I saw applications out there to allow people do it. Twitter provides such APIs, and I’ve noticed that there are apps out there that enable auto-posting. Any ideas?
Pumpkin on February 6th, 2010
Apologize.. if my visitor doesn’t logged in yet, the application will prompt username and password of their FB, confirmation to update status to get the ID. how the code would be? could anybody please help me ? thanks before..