Figure 1. Locate facebook.php in Facebook Library Folder
<?php
require_once 'php/facebook.php';
$appapikey = 'INPUT YOUR APP KEY HERE';
$appsecret = 'INPUT YOUR APP SECRET KEY HERE';
//create the object
$facebook = new Facebook($appapikey, $appsecret);
/**
* Check if we have an already logged in user ?
* Yes - Skip the require_login
* No - User is redirected to facebook login page
*/
if(!is_numeric($facebook->get_loggedin_user()) || !$facebook->api_client->users_hasAppPermission("publish_stream"))
$facebook->require_login($required_permissions = 'publish_stream');
/**
* In case user reaches here and our application doesn't have proper permissions to publish,
* then display this error message
*/
if(!$facebook->api_client->users_hasAppPermission("publish_stream"))
{
echo 'Darn !! Something just broke !!' ;
}
/**
* Check if we have Post data and a status to update
*/
if($_POST['update_me'] == 1)
{
$res=$facebook->api_client->stream_publish($_POST['st'],'');
$uid = $facebook->get_loggedin_user();
$tmp = explode ("_",$res);
if($uid == $tmp[0])
{
echo "Timeline updated successfully, <a href='http://www.facebook.com/?id=$uid'> Go back to your profile page</a>";
}
else
{
echo "Couldn't update your status, Please try again";
}
}
/**
* Display the form to update status
*/
else
{
?>
<form method="POST" action="http://www.your_domain.com/index.php" >
<input type="hidden" value="1" name="update_me"/>
<textarea name="st"></textarea> <br>
<input type="submit" value="Update status" />
</form>
<?php
}
?>
require_once to match your folder hierarchy.require_login function, but the problem with require_login is that it redirects so often that any post data to your page is lost. So, you have put a check before calling the require_login function. In the same line, you also check whether or not your application has permission to post updates onto a user's stream. If you do not have permission, the user is prompted to allow your application.userid_postid is returned. If it fails, then different error codes are returned. Find a list of error codes on Facebook's wiki page.