Facebook Status updates using php SDK

Posted by Unknown On Friday, 21 December 2012 0 comments

It’s our new tutorial about Facebook status update using php SDK, you can update your Facebook status using simple PHP code and Facebook Graph API. This is the most na├»ve way to use this; you can extend this to make your own script to update your status from mobile.


Ok let’s get started now! To be very frank, the status update script is already there in the SDK provided by Facebook, but very few people know. And there are people who won’t even know how easy it is.


1.      Create a Facebook app.

Login to Facebook and go to http://www.facebook.com/developers Click on the button at top right where it says “+ Set up New App”

Now let’s give a name to your app.

Next is to put the Canvas Page and Canvas URL. This Canvas Page will be used to Canvas URL is the location from where Facebook pulls all the content of your APP.

You will see your application’s unique App ID, API Key, App secret, keep it safe and we are going to use these in our example.

2.      Install Facebook php SDK.

You can download the latest version of SDK from https://github.com/facebook/php-sdk/and hit download.

 I have downloaded the latest version which is 2.1.2 till date.

We are going to use src folder which has the necessary code to interact with the Facebook API. Upload this folder to thehttp://yourdomain.com/fb-app-folder

download source code


3. Create php status update code and add secret code and app id.

 Create your file which will update the status, call it as

 index.php .

<h1>Facebook Status Update</h1>
<?phpif ($_SERVER["REQUEST_METHOD"] == "POST") {
$status      $_POST['status'];
$facebook_id $userdata['id'];
$params      = array(
'access_token' => $access_token,
'message' => $status
$url         "https://graph.facebook.com/$facebook_id/feed";
$ch          curl_init();
curl_setopt_array($ch, array(
CURLOPT_URL => $url,
$result curl_exec($ch);
// End
echo "<span style='color:#cc0000'>Message Updated</span>";
<form method="post" action="index.php">
<textarea name="status"></textarea> <br/>
<input type="submit" value=" Update "/>


Post a Comment