Facebook Application About Page

5 Steps to publish on a facebook wall using php

Since Facebook has stopped supporting Java we need to use PHP for now to post on a wall.

According to facebook Wiki posting on a  wall is very confusing and very difficult to write a program to publish on a wall.

I spent around 2 weeks reading many articles and many documents, Wiki on facebook but in vein and tried many ways and finally I got one workable model. Below are 5 simple steps to publish on a Facebook wall.

Step1: Login to Facebook to Create a Facebook App

First login to Facebook and goto the url http://www.facebook.com/developers/ then

Click on “+ Set Up New Application” button to start creating the application as shown below.

Create New Facebook application

Provide the application name, click agree for facebook terms and click on “Create Application” button.

Fill in application Name

create app step1

Now Application is created for you. Just copy the Application API Key, Application Secret and Application ID details which will be used to write the application code.

Fill the Name and Description of your application in About Link.

Facebook Application About Page

Now Click on Website Link to get API Key

Facebook Application web Site

Now goto Facebook Integration link and enter any url. Here is where you will get Secret Key.

Enter the Canvas URL and page name. This will be the return URL of your Application.

Facebook Application Facebook Integration

That’s it You now just successfully create a Facebook Application, now lets work on program

Then click on Save. That’s it we have created a facebook application with an Iframe.

Now Copy Application API Key, Application Secret and Application ID details which will be used to write the application code.

Now download the php library from facebook “http://blog.theunical.com/wp-content/uploads/2010/05/facebook-platform.tar.gz

Step2: Generate One Time Token to generate Session key

How to generate One Time Session key:

Run below URL to get temporary token for the particular user by logging into Facebook.


Note: Please replace “API_KEY” with your application API key from above page.

Then we will get a temporary token key.


generatemylogin info


This is one time token key that we can use to generate a permanent session key. Careful! Don’t try to execute this programs many times

Step3: Generate one time session key (permanent session key)

Below is the sample PHP code to generate one time session key.


// FB_APIKEY is your facebook application api key

// FB_SECRET is your application secrete key



$fb = new FacebookRestClient($FB_APIKEY, $FB_SECRET);

$testtoken= "ONETIMETOKEN"; // Replace this value with your Token Value

$result = $fb->call_method('facebook.auth.getSession',

array('auth_token' => $testtoken, 'generate_session_secret' => true));

echo "<br /><pre>";


echo $session_key = $result['session_key'];



For example, the full URL for logging in a user could be:


If the user is redirected to the URL specified by the next parameter, then Facebook grants your application a session. This session is appended to the URL as a JSON-decodable object of the form:

&session={“session_key”:”SESSIONKEY”, “uid”:USERID, “expires”:0 || UNIXTIME, “secret”:”SESSIONSECRET”}

In continuing with the above example, the redirect for a successful login would be:


If the user grants your application the offline_access extended permission, 0 gets returned for expires and the session never expires unless the user removes the application. In this case, you should store the session key so the user doesn’t have to log in the next time he or she launches your application.

Note: The above code will execute only once. We should note down the above session key, This will be used to auto login into the application.

If you don’t save these session key values you should generate other token key to create one time session key.

We can use the token only once.

Step4: Setting Permission for wall

Giving Permission to your application to publish on facebook wall. To give permission just replace the your API key in below URL and execute in browser.


Then you must see the below 3 Screens

If you don’t see the below then your call back URL or Canvas URL must be incorrect, please check again your application settings and execute the URL again.



Then on final page, you will see a success message.  That’s it you have given permission for read_stream,publish_stream and offline_access.

Step5: Publishing the message on Facebook Wall

PHP Code to create facebook object with onetime session key and publishing the message on Facebook Wall.




define('FB_SESSION', 'YOUR_SESSION_key');


echo "post on wall";

try {

$facebook = new Facebook(FB_APIKEY, FB_SECRET);

$facebook->api_client->session_key = FB_SESSION;

$fetch = array('friends' =>

array('pattern' => '.*',

'query' => "select uid2 from friend where uid1={$user}"));

echo $facebook->api_client->admin_setAppProperties(array('preload_fql' => json_encode($fetch)));

$message = 'From My App: publish steven on facebook';

if( $facebook->api_client->stream_publish($message))

echo "Added on FB Wall";

} catch(Exception $e) {

echo $e . "<br />";



Now you will see the post on wall Great.

published on facebook

So thrilling isn’t we can also publish photos videos on wall.

In my next post see how to publish images and videos to facebook is done



See here how to publish on facebook page as a facebook user


have a great day

— Steven

Steven Fan Page on Facebook

Please don’t copy this content to any site. This is fully protected by TheUnical Technologies

Post Laster Updated on 13 March 2011

308 thoughts on “5 Steps to publish on a facebook wall using php”

  1. Ok… I followed the tutorial and it does what it says, but not what I thought it was going to do. Do you know how I can have the application post to its own wall?

    For example if a user of the site does something, I want the site to post to the application wall so all that like the application will get that as part of the news feed.

    I can’t seem to find this anywhere.

  2. hi!
    Steven Robert
    First thanx for posting the good article …i also doing this but one problam come that when i give the url of canvas and connect after that click save button i found a error that your api key is invalid..what’s problam ..and i also want to know in canvas and connect url which links will be given..please help me….

  3. hi Steven Robert
    good morning
    after complted the first step when i start step to and click the given url then i found a error like this(‘Invalid API key specified’.).what’s the mistake..please solve this problam..
    for your help and support

  4. @Dinesh for Step2 don’t run it directly on it just replace your APIkey and open it in browser. And for Step3 It will generate a unique session key just use it for Step5

  5. Class ‘Facebook’ not found in /var/vhosts/apartmentsneakpeeks/httpdocs/facebook-platform/php/facebookapi_php5_restlib.php on line 82

    Rest was fine but in the last due to session value is “” i could not make the post done.

    Will you please mail me regarding this.
    Thanks and Regards,

  6. Hi Steven,

    can you assist me with an API for FB offline messages..am unable to do that..

    The script you mentioned here is for the online messages not offline

    Thanks in advance

  7. everything is working nice, thanks for the script.

    What about character encoding? Accent characters not shown. I do not find how to set char set

  8. Hi Steven,

    I need to post comment on my application users selecting from my data base but very confused in that. There are a number of ways given on the net apart from each other . I just setup tha application. Now want that the user who add the application his user id will be stored in my database and I can post some kind of rank for each users from my db

  9. One strange problem i got is that.. when i first went on with the steps i got my postings to my wall. I tried it for another facebook profile and didnt succeed.Again i replaced the old code in my server and tried toxecute post to wall. now i am getting
    123exception ‘FacebookRestClientException’ with message ‘Session key invalid or no longer valid’ in /home/socialcr/public_html/beta/facebook/fb_app/facebook-platform/php/facebookapi_php5_restlib.php:3025 Stack trace: #0 /home/socialcr/public_html/beta/facebook/fb_app/facebook-platform/php/facebookapi_php5_restlib.php(2882): FacebookRestClient->call_method(‘facebook.admin….’, Array) #1 /home/socialcr/public_html/beta/facebook/fb_app/publish on wall.php(16): FacebookRestClient->admin_setAppProperties(Array) #2 {main}

    Then with the above key execute the below URL in browser to give access to your program.

    Plz make me clear with this…..

  10. Hi stephen… when i was posting $message value iam exactly getting the message displayed in facebook wall .
    example :$message=”34% post opinions about products and brands on their blogs – Interested in profiting from social media? Try http://ow.ly/16C88 “;
    It is posting well.
    but when i tried to retrieve the same messages from my database like $message=mysql_fetch_row($tag_query); the message is displayed as

    ‎[“34% post opinions about products and brands on their blogs – Interested in profiting from social media? Try http:\/\/ow.ly\/16C88\r”]
    plz make me clear with this mate
    Thanks in advance

  11. I got this error….. Any help plz…..

    post on wallexception ‘FacebookRestClientException’ with message ‘Invalid API key’ in /home/snauman/public_html/therunaround/facebook-client/php/facebookapi_php5_restlib.php:3025 Stack trace: #0 /home/snauman/public_html/therunaround/facebook-client/php/facebookapi_php5_restlib.php(2882): FacebookRestClient->call_method(‘facebook.admin….’, Array) #1 /home/snauman/public_html/therunaround/Udefinesuccess/index.php(27): FacebookRestClient->admin_setAppProperties(Array) #2 {main}

  12. I would like to know if we can do both requesting permissions and executing our code in the same page,

    because when i make the user type in the following url,


    i cannot check whether he has successfully done it.

    ne ideas will be greatly thankful

  13. Hi!

    Great post!
    I would like to ask your help. I have multiple pages, created with open graph protocol, and I want to post on the page’s wall. The problem is, that the pages are created dynamic: when there is an event, I store it in a database, and I generate an open graph protocol page for the event.
    How can I post to the page’s wall? I tried putting the page’s url as target_id, but no result; I tried your code, but I’m stuck at step 3 (104 Incorrect signature method facebook.auth.getSession session_key api_key [my_app_key] v 1.0); and a few other things, but no result. 🙁
    Any help would be appreciated!

  14. Hi All,

    I’m new to developing for Facebook so sorry if my question is a stupid one!
    I would like to set up the above example but I always get an error at Step 2.

    The error is :
    API Error Code: 100
    API Error Description: Invalid parameter
    Error Message: next is not owned by the application.

    Anyone who can help me?



  15. HI,
    I keep on getting stuck in step #4,
    I get the following message:
    “To fix this error, please set your Connect URL in the application settings editor. Once it has been set, users will be redirected to that URL instead of this page after logging in.”
    What can the problem be?
    Please can anyone help – I’m stuck!!!!!

  16. Hi,
    Thanks for this lovely article. This article is very help full for me and i am able to post on user wall text as well as image but my problem in step 3 calling URL from browser its working but i want to fetch the user offline session-id from my web page using this URL how can i achieved this or any alternate way is there for getting user offline session-id?

    Using java.

    Please help me.

    Thanks allot.

  17. hey steven , nice article , but i a newbie with fb development. i want to create a poll application . i can handle the php stuff . but i want my application to post of on friends (of the current app user) wall. is that possible ? if yes can you direct me to the right direction.

    and i have seen applications that do automatic posting on user’s friends walls at random , any tips or links on how that can be achieved.

    your blog is awesome.


  18. Hi Steven,

    Thank you very much for reply,

    But now i am able to fetch the user offline session id using FB JavaScript.

    Thanks alot.


  19. Hi ,Dude

    1. Could you plz inform me where i have to use step 3 and 5.

    2. where i have to use save my login info code.

    3. finally , i got worked up with this code and the result is login page as well as request page i grant the permission “allow” after that this code is not responding itz still loading..

  20. I did not see the Connect link in my application.
    I only see About, Website, Facebook Integration, Mobile and devices, Advanced links.
    Please help …


  21. I have follow all the step of ur steps. But when i run ur code, it said Call to undefined method stdClass::admin_setAppProperties(). Can u help me pleas?

  22. Hi Steven, Thanks a lot. I have been struggling to post to my fan page wall using php for last three weeks. Now I’m able to post to my own wall, and its a great step towards my goal.

    actually I’m creating a free for all application where the people can publish messages, photos, videos, events to their pages.

    Please guide me how to publish the message on fan page wall.

    Thanks in advance

  23. Hi Steven,

    Thanks for your great tutorial!

    Sorry to digress. But how do I allow users to register and login using their Facebook account? (the single sign-on) I cant seem to integrate Facebook with Webid for the login part. How do I authenticate users who have registered using their Facebook account to use my site & post the above news feed?

    I’m using PHP, thanks! Hope to get a reply from you soon!

  24. I’m getting the same error as @185, Steven can you please confirm that this is actually working? I can’t see any way of getting around this.

  25. Hi Happismile,

    If you follow all the steps described here, there should be not problem.
    In step 3, you will get permanent session key which will be used for logging in to facebook from your site. If your site has more than one users, then you can same their session keys in local database, that session key will be used for posting, or viewing the facebook data for that user.

    Please let me know where you are facing the problem.


  26. Hello Steven, Thanks for your help!

    Today the facebook API on step 2 suddenly worked so every thing is ok.

    I have a new question, I need to post a message to a Page I own (and not to my user), can you point me to the right direction?

  27. Hi Balijeet

    Thank you for your prompt response!

    I’m using localhost as my testing server. So after I completed the 5 steps above, I’m the only Facebook user able to publish on Facebook wall.

    I want to allow other Facebook users who use my site to also publish on Facebook wall. How do I get their session key using PHP for Step 2 & 3 and then save it to my database?


  28. Hi Happy, sorry for the late response due ti weekend.
    If you ready the steps properly and know php, there should be no problme. Further, you can give my you email id, I’ll send the code I have done in php, with explanation.

  29. Hi Balijeet

    My email address is cbx006@gmail.com.

    Anyway, does anybody know whether Facebook change their api again? I cant access my “Connect to Facebook” button since yesterday. ):


  30. hi i have understood and it works for me if i do manually setp 2 and 3.

    i want my php script to perform step 2 and step 3 automatically when user login into my app. how can i do it?

  31. Hi Gaurav,
    2nd and 3rd steps can be merged and can be automate dusing php. You just need to call below url (make sure yiu replace value of next quesry string to the url where you want to redirect after success.):


    If you are looking for ready-made php script for this go here
    I have created this a sample script based on the steps discussed here by Steve.

  32. great tutorial! … but I at step 2 I am getting the same error message as @185 and @188: “An error occurred. Please try again later.” tried different things but can’t get it work:( … not sure if I selected “Web” app correctly, the facebook interface for creating apps changed in the meantime. and re Canvas URL, can I type in any random URL or does it need to be a specific one? cheers!

  33. I am able to send only plain text. When I send some HTML tags like <img… it does not work. Is there any solution to send to facebook wall HTML text too?

Leave a Reply

Your email address will not be published. Required fields are marked *

To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Anti-spam image