Post update on user wall using Facebook’s Graph API

  1. Previous
  2. Next
  3. Recent

    1. Complete Company Registration Process in India - Explained
    2. Change Name in India in 5 Steps - Filing Affidavit, Newspaper Ad & Gazette Notification
    3. 5 Best Websites for Searching Trains in India
    4. Smartphone Operating Systems that Will make it Big in 2015
    5. Can I use Infolinks and AdSense ads together on the same page?
    6. How to Insert AdSense Ad within Post Content in WordPress (without Plugin)
    7. How to Book Newspaper Ads Online from Home
    8. 11 Killer Tips to Increase CPC of Adsense Ads
    9. How to Choose Best Web Hosting Service for Website: Best Tips
    10. What is Document Open Password for Aadhar Card

Facebook’s Graph API simplifies the exchange of user data with the Facebook servers. An app can inquire about user’s private information including feeds, comments and likes, see his connections with friends, and do lot more stuffs in easy steps.

Using Graph API, a Facebook app can also make post on user’s wall after getting permission.

Today we build Facebook application that post on user’s wall by making HTTP POST request to Graph API.

1. Get User Authentication

First we need to get user authentication with permission to post updates on his behalf [publish_stream permission].

Here is the total syntax for making such authentication request,

 $auth_url = "" . $app_id . " &redirect_uri=" . urlencode($canvas_page)."&scope=publish_stream";

echo("<script> top.location.href='" . $auth_url . "'</script>");

For an app named(namespace) ‘post-on-user-wall’, with app_id=’12345689′ the authentication url would look like,

 $auth_url = " &redirect_uri=" . urlencode('')." &scope=publish_stream";

echo("<script> top.location.href='" . $auth_url . "'</script>");

2. Get Access Token

Once our app is given authentication, we need the access token. Access token is needed to tinker with user data. As we’ll be publishing updates, so we need access token here too.

2.1 Before getting access token, include Facebook php sdk files in your app.

<?php require_once('../facebook-php-sdk/src/facebook.php'); ?>

2.2 We’ll get access token by calling function of Facebook php sdk.

<?php $access_token = $facebook->getAccessToken(); ?>

3. Post update

Now we have everything we needed to post on user’s wall. Its time to take user input. We’ll take this input and post to his wall.

We add a textarea to take the input. Then we call to JavaScript function ‘posttofeeds()’ that’ll make HTTP POST request to Graph API to publish update.

<form method='POST' id='flipform'>

<textarea name='outputdata' id='outputdata' class='iodata'></textarea>
<input type='button' class='but' value='Post my update' id='sub' onclick=posttofeeds('<?php echo $access_token; ?>')>


Since we’re making Ajax call using jQuery, first we download the jQuery file and then make the call to Facebook’s Graph API.

<script src=""></script>

<script language='Javascript'>

 function posttofeeds(token)
 var param='access_token='+token+'&message='+flipform.outputdata.value;
 $.post('',param,function(data){alert('Update posted to user wall');});


That’s all! In the example, an alert will show up when update is posted successfully.

Unlike us, most applications on Facebook make the same HTTP POST Request using JavaScript SDK. JavaScript SDK is a bulk sized file which can make an app slow. Slow Facebook apps often throw CurlException which can render an app unusable.

blog comments powered by Disqus