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.

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

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.

Now goto Canvas link and enter any url.

Next goto Connect URL link and enter the same url.

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.
https://login.facebook.com/code_gen.php?api_key=API_KEY&v=1.0
Note: Please replace “API_KEY” with your application API key from above page.
Then we will get a temporary token key.



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.
<?php
// FB_APIKEY is your facebook application api key
// FB_SECRET is your application secrete key
$FB_APIKEY="YOUR_API";
$FB_SECRET="YOUR_SECRET";
$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>";
print_r($result);
echo $session_key = $result['session_key'];
?>
(OR)
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:
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.
http://www.facebook.com/login.php?api_key=APIKEYXxxxxxxxxxxxxxxxxx&connect_display=popup&v=1.0&next=http://www.facebook.com/connect/login_success.html&cancel_url=http://www.facebook.com/connect/login_failure.html&fbconnect=true&return_session=true&req_perms=read_stream,publish_stream,offline_access
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.
<?php
define('FB_APIKEY', 'YOUR_APIKEY');
define('FB_SECRET', 'YOUR_SECRET');
define('FB_SESSION', 'YOUR_SESSION_key');
require_once('facebook-platform/php/facebook.php');
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.

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
http://blog.theunical.com/facebook…/add-picture-on-facebook-wall-using-php/
http://blog.theunical.com/facebook…/post-video-on-facebook-wall-using-php/
See here how to publish on facebook page as a facebook user
http://wiki.developers.facebook.com/index.php/Stream.publish
have a great day
– Steven
Please don’t copy this content to any site. This is fully protected by TheUnical Technologies
Similar Posts
- » Saturday Word: Fort Hood and Health Care - The Caucus Blog <b>...</b>
- » Google Search: This week in search 6/27/10
- » sephone blog » More Big Numbers
- » Interview: Nokia Sheds Light on Smartphone Future
- » Now Available - Sun Studio 12 Update 1 Multi-Language Release
Comments
153 Comments on 5 Steps to publish on a facebook wall using php
-
Mustafa on
Sun, 1st Nov 2009 7:16 am
-
Ramachandran on
Wed, 11th Nov 2009 7:20 am
-
Steven Robert on
Wed, 11th Nov 2009 11:06 pm
-
Hardik on
Wed, 2nd Dec 2009 6:32 am
-
Steven Robert on
Wed, 2nd Dec 2009 1:13 pm
-
chad james on
Sat, 26th Dec 2009 6:06 am
-
Steven Robert on
Sat, 26th Dec 2009 10:53 pm
-
vishal on
Thu, 31st Dec 2009 9:05 am
-
Steven Robert on
Thu, 31st Dec 2009 11:02 pm
-
vishal on
Fri, 1st Jan 2010 3:42 am
-
Steven Robert on
Fri, 1st Jan 2010 9:45 pm
-
vishal on
Mon, 4th Jan 2010 5:15 am
-
Steven Robert on
Mon, 4th Jan 2010 9:47 pm
-
Vishal on
Mon, 11th Jan 2010 6:41 am
-
Steven Robert on
Mon, 11th Jan 2010 10:53 pm
-
Tomee on
Fri, 15th Jan 2010 3:37 am
-
Steven Robert on
Fri, 15th Jan 2010 10:56 pm
-
Steven Robert on
Fri, 15th Jan 2010 10:58 pm
-
Tomee on
Sat, 16th Jan 2010 9:00 am
-
Steven Robert on
Mon, 18th Jan 2010 12:44 am
-
shyam on
Tue, 19th Jan 2010 9:20 am
-
Steven Robert on
Wed, 20th Jan 2010 4:32 am
-
Steven Robert on
Wed, 20th Jan 2010 4:33 am
-
Maria on
Thu, 21st Jan 2010 7:37 pm
-
Maria on
Thu, 21st Jan 2010 7:40 pm
-
Maria on
Thu, 21st Jan 2010 7:54 pm
-
Steven Robert on
Thu, 21st Jan 2010 10:50 pm
-
Steven Robert on
Thu, 21st Jan 2010 10:51 pm
-
Steven Robert on
Thu, 21st Jan 2010 10:53 pm
-
Tomee on
Fri, 22nd Jan 2010 11:16 am
-
Steven Robert on
Fri, 22nd Jan 2010 10:52 pm
-
Tomee on
Sat, 23rd Jan 2010 6:49 am
-
Steven Robert on
Sat, 23rd Jan 2010 10:56 pm
-
Fabio on
Mon, 25th Jan 2010 11:08 pm
-
Steven Robert on
Mon, 25th Jan 2010 11:10 pm
-
Fabio on
Tue, 26th Jan 2010 7:32 am
-
Steven Robert on
Tue, 26th Jan 2010 10:11 am
-
shyam on
Thu, 28th Jan 2010 5:52 am
-
Steven Robert on
Thu, 28th Jan 2010 9:59 pm
-
shyam on
Fri, 29th Jan 2010 1:15 am
-
faemino on
Fri, 29th Jan 2010 8:31 am
-
Maria on
Fri, 29th Jan 2010 3:24 pm
-
Steven Robert on
Fri, 29th Jan 2010 9:58 pm
-
Rangga on
Sat, 30th Jan 2010 7:24 am
-
Jim on
Sat, 30th Jan 2010 3:48 pm
-
Steven Robert on
Sat, 30th Jan 2010 11:16 pm
-
fede on
Mon, 1st Feb 2010 2:58 pm
-
Sebastien on
Wed, 3rd Feb 2010 10:09 am
-
Steven Robert on
Wed, 3rd Feb 2010 9:57 pm
-
Aziz on
Thu, 4th Feb 2010 9:33 am
-
Kapil Jadhav on
Fri, 5th Feb 2010 9:10 am
-
Aziz on
Mon, 8th Feb 2010 6:07 am
-
roded on
Mon, 8th Feb 2010 11:53 am
-
Keval on
Wed, 17th Feb 2010 8:11 am
-
TheTester on
Fri, 19th Feb 2010 7:16 am
-
Steven Robert on
Fri, 26th Feb 2010 12:22 am
-
Sylvester Faro on
Thu, 4th Mar 2010 6:48 am
-
Steven Robert on
Thu, 4th Mar 2010 9:52 pm
-
abrahan on
Mon, 8th Mar 2010 8:33 pm
-
Steven Robert on
Mon, 8th Mar 2010 10:45 pm
-
Dinesh on
Mon, 15th Mar 2010 4:02 pm
-
navjot singh on
Tue, 16th Mar 2010 6:42 am
-
Steven Robert on
Tue, 16th Mar 2010 9:01 am
-
Dinesh on
Tue, 16th Mar 2010 9:36 am
-
Steven Robert on
Tue, 16th Mar 2010 10:04 am
-
Sylvester Faro on
Thu, 18th Mar 2010 7:13 am
-
Bruno Gomes on
Thu, 18th Mar 2010 10:47 pm
-
Chandan on
Fri, 19th Mar 2010 12:06 am
-
Chandan Singh on
Fri, 19th Mar 2010 2:20 am
-
Steven Robert on
Fri, 19th Mar 2010 4:26 am
-
Steven Robert on
Fri, 19th Mar 2010 4:29 am
-
Steven Robert on
Fri, 19th Mar 2010 4:51 am
-
bruno gomes on
Fri, 19th Mar 2010 11:00 am
-
tippi on
Fri, 19th Mar 2010 1:57 pm
-
Steven Robert on
Fri, 19th Mar 2010 10:59 pm
-
Steven Robert on
Fri, 19th Mar 2010 10:59 pm
-
Nick on
Wed, 24th Mar 2010 3:16 am
-
Luca on
Wed, 24th Mar 2010 10:16 am
-
Luca on
Wed, 24th Mar 2010 6:45 pm
-
Sammy on
Thu, 25th Mar 2010 3:17 am
-
Steven Robert on
Thu, 25th Mar 2010 10:20 am
-
Steven Robert on
Thu, 25th Mar 2010 12:00 pm
-
Saurabh on
Sun, 28th Mar 2010 1:52 pm
-
Steven Robert on
Sun, 28th Mar 2010 10:46 pm
-
kirochi on
Mon, 29th Mar 2010 12:10 pm
-
Mirza on
Tue, 30th Mar 2010 11:52 pm
-
Steven Robert on
Wed, 31st Mar 2010 4:09 am
-
Rami on
Tue, 6th Apr 2010 8:11 am
-
sunetra on
Fri, 9th Apr 2010 6:57 am
-
Steven Robert on
Sat, 10th Apr 2010 9:58 am
-
sunetra on
Sun, 11th Apr 2010 2:00 am
-
Steven Robert on
Sun, 11th Apr 2010 4:31 am
-
Omar Plummer on
Tue, 13th Apr 2010 11:24 pm
-
Iva on
Fri, 16th Apr 2010 9:29 am
-
newbie on
Thu, 22nd Apr 2010 6:31 am
-
darrasin@freedom.com on
Fri, 23rd Apr 2010 5:45 pm
-
Rio MobineSSia on
Fri, 23rd Apr 2010 11:57 pm
-
Steven Robert on
Sun, 25th Apr 2010 8:02 am
-
Steven Robert on
Sun, 25th Apr 2010 8:22 am
-
BKC on
Sun, 25th Apr 2010 1:20 pm
-
newbie on
Sun, 25th Apr 2010 1:22 pm
-
Steven Robert on
Sun, 25th Apr 2010 9:34 pm
-
Steven Robert on
Sun, 25th Apr 2010 9:36 pm
-
Felix Gomez Jr on
Mon, 26th Apr 2010 12:25 pm
-
Steven Robert on
Mon, 26th Apr 2010 9:42 pm
-
Aarif on
Wed, 28th Apr 2010 9:13 am
-
Steven Robert on
Wed, 28th Apr 2010 10:47 pm
-
dina on
Sun, 2nd May 2010 3:00 am
-
dina on
Sun, 2nd May 2010 9:00 am
-
Steven Robert on
Sun, 2nd May 2010 9:01 am
-
dina on
Mon, 3rd May 2010 3:10 am
-
Girl games on
Wed, 5th May 2010 6:03 am
-
Aziz on
Tue, 11th May 2010 5:48 am
-
Steven Robert on
Tue, 11th May 2010 8:19 am
-
Aziz on
Tue, 11th May 2010 9:07 am
-
Steven Robert on
Tue, 11th May 2010 11:35 pm
-
Aziz on
Wed, 12th May 2010 5:05 am
-
nikhil on
Thu, 13th May 2010 8:10 am
-
Steven Robert on
Thu, 13th May 2010 8:35 am
-
nikhil on
Thu, 13th May 2010 8:45 am
-
Steven Robert on
Thu, 13th May 2010 10:42 am
-
Edgar on
Mon, 17th May 2010 10:06 am
-
lilongsy on
Tue, 18th May 2010 11:37 am
-
lilongsy on
Tue, 18th May 2010 11:38 am
-
lilongsy on
Tue, 18th May 2010 11:43 am
-
Namalak on
Wed, 19th May 2010 8:42 am
-
Kuldeep singh on
Fri, 21st May 2010 4:28 am
-
Krishna on
Mon, 24th May 2010 8:23 am
-
Anulya on
Fri, 11th Jun 2010 5:16 am
-
saran on
Tue, 15th Jun 2010 10:05 am
-
kamarul on
Wed, 16th Jun 2010 6:49 am
-
Junior on
Mon, 21st Jun 2010 4:40 am
-
piv64 on
Mon, 21st Jun 2010 8:47 am
-
Steven Robert on
Mon, 21st Jun 2010 11:03 pm
-
Steven Robert on
Mon, 21st Jun 2010 11:04 pm
-
piv64 on
Tue, 22nd Jun 2010 5:39 am
-
Junior on
Tue, 22nd Jun 2010 10:08 am
-
Steven Robert on
Wed, 23rd Jun 2010 12:13 am
-
Junior on
Wed, 23rd Jun 2010 7:02 am
-
Steven Robert on
Wed, 23rd Jun 2010 10:11 am
-
orkut scraps on
Thu, 24th Jun 2010 3:20 pm
-
Mr Blass on
Sat, 26th Jun 2010 9:50 pm
-
Junior on
Sun, 27th Jun 2010 12:44 pm
-
Ernestas on
Mon, 28th Jun 2010 6:34 pm
-
dinesh on
Wed, 7th Jul 2010 3:27 pm
-
Joomla Outsource India on
Sat, 17th Jul 2010 6:39 am
-
Steven Robert on
Sun, 18th Jul 2010 5:15 am
-
Joomla Outsource India on
Sun, 18th Jul 2010 11:07 am
-
Jeff on
Thu, 22nd Jul 2010 5:40 pm
-
Jeff on
Thu, 22nd Jul 2010 6:02 pm
-
Steven Robert on
Thu, 22nd Jul 2010 11:44 pm
-
Jeff on
Sat, 24th Jul 2010 9:41 am
-
Joomla Outsource India on
Sat, 24th Jul 2010 11:38 pm
Excellent:
Here is another way to Publish on Facebook Wall Using JSON using Coldfusion:
http://blog.abusalah.info/2009/05/publish-on-facebook-wall-using-json-fb.html
Nice script, thanks for your script…..
when i use this script .I am getting the error as 104(incorrect signature).
And we can able to run the script suceessfully upto step 4.But i am struck in the STEP 5 because of this error .
Do you aware of this error?
How to fix this.
Any input is appreciated.
After step4 did you see the privilege screen from facebook.
we need to give permissions to publish on facebook. Let me know if you have any questions.
hello,
i have followed the instruction word by word and i have also succed.But I have one doubt thats is where should I use that two script.
I am developing an iphone application which connect to facebook.thats i will login on facebook through my iphone and after login i want to publish on my wall as well as user walls directly.I hope you understand what my doubt is.
Yes u can do that. If you have the api key and secret key. You need to save this keys in ur application.
Hey I created a facebook application for my blog called QIT Interact, The problem I’m running into is I’m new to all this etc and I’m trying to work out if there is way that I can have my application published to feeds say when a new post has been posted etc rather then looking up the application etc. Ideally what I’m wanting to do is rig it so it will always send a message to streams any help would be greatly appreciated
Yes, We can. what kind of application you are building
I am trying to publish my offline data on facebook but its not giving me any response.. below is my script .. please give me solutions .
api_client->session_key = $_REQUEST['fb_sig_session_key'];
$facebook->require_frame();
$user = $facebook->require_login();
$userinfo = get_prints($user);
$name = $userinfo[0]['title'];
$description = $userinfo[0]['description'];
$attachment = array(’name’ => $name, ‘href’ => ‘http://apps.facebook.com/vishpoint/’, ‘description’ => $description, ‘media’ => array(array(’type’ => ‘image’, ’src’ => ‘http://www.jaisiyaram.com/adv/banners/23-1-1260415655.jpg’, ‘href’ => ‘http://apps.facebook.com/vishpoint/’)));
$action_links = array(array(’text’ => $name, ‘href’ => ‘http://apps.facebook.com/vishpoint/’));
$attachment = json_encode($attachment);
$action_links = json_encode($action_links);
$has_permission = $facebook->api_client->users_hasAppPermission(”publish_stream”);
//echo $has_permission;
$ans=$facebook->api_client->stream_publish(”Testing.. “,$attachment,$action_links);
if($ans){
echo “Added on FB Wall”;
}else{
echo “Not Added on FB Wall”;
}
}catch(Exception $e) {
echo $e . “”;
}
?>
You cannot connect to facebook offline.
Hi Steven, Actually i want to post my data from my pc on the facebook wall.. like image, title and description by above script…Is it possible? how?
Yes but the image should be in a public path like it should be accessible from any where.
HI steven,
I have admin section on my website. I am updating news content on website daily. I want to publish same content on my facebook account wall. What I want is when I submit content in my websites’s admin area, it should also update facebook wall with same contents.
I have set up facebook application and grab the API Key and other required information. I am using iframe and not fbml.
I am using stream_publish() function.
Problem is here when I submit data using stream_publish, it redirects me to login page.
Is there any method through which I can login to facebook and publish content to my facebook wall.
Below is the code.
require_frame();
$user = $facebook->require_login();
$attachment = array(’name’ => $name, ‘href’ => $link, ‘description’ => $description, ‘media’ => array(array(’type’ => ‘image’, ’src’ => $imagelink, ‘href’ => $link)));
$action_links = array(array(’text’ => $name, ‘href’ => $link));
$attachment = json_encode($attachment);
$action_links = json_encode($action_links);
$facebook->api_client->stream_publish($description,$attachment,$action_links);
?>
Please help.
Thanks in advance.
Hello Vishal,
You need to complete Step 2, 3, 4 to create a one time session key and give permission to publish on wall. so that next time it will not ask you to login to facebook.
Let me know if you done these correctly.
Hello
I tried to perform all steps mentioned below.
1) I have created application as mentioned.
2) I have retrived one time session key.
3) I have granted permission as well.
4) In application setting, I have canvas call back url, this would call the script in step 5.
Now what I do is I logged out from facebook. Then I typed url in address bar as http://apps.facebook.com/theunicalblogtest/
This shows me “Sign up for Facebook to use Blog TheUnical.”
What I am doning wrong here? can you please let me know here?
Hi Vishal,
Why you want to type this URL “http://apps.facebook.com/theunicalblogtest/”. you can just execute your program.
Hi there,
the code from the step 3 where should be copied to run, ‘couse saving to a file and just run it does not gives you a valid response.
Just Copy the php code and replace with your keys and execute to generate a one time session key. Tomee, you need to execute this only once, if you try to execute this 2nd time you will get some errors.
Tomee, If you get errors then try again from step2.
i obtained the one time code Steven, and the API code and secret also. When I run the file it gives me the “FacebookRestClient” undefined function error, which is kinda normal I think ‘couse it is nowhere defined in the php file.
Hi Tomee here is the same code that is working for my id , replace with your’s and try. http://blog.theunical.com/?attachment_id=267142.
let me know if you still have any issues.
I follow the instruction but i have a problem when i am trying to generate session since there is class page in not included in STEP 3 so firstly is say class not found and even after adding the related class now is saying
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,
SHyam
Shyam did you tried downloading the code from here? http://blog.theunical.com/?attachment_id=267142
Shyam did you tried downloading the code from here?
http://blog.theunical.com/?attachment_id=267142
Steven, I cannot execute step 3. Is the php code supposed to be executed on a server? I have plugged in my values, but I get php parsing errors.
Plus, line 11 in step 3 should be:
$fb = new FacebookRestClient($FB_APIKEY, $FB_SECRET);
FB_APIKEY and FB_SECRET are php variables. And should the code not include the facebook php library? I am very confused.
And finally, this link does not show any code
There is a link that you can download from, check again.
This is that link http://blog.theunical.com/wp-content/uploads/2010/01/fb_app.zip
Maria, This should be replaced by facebook secret key and facebook app key
Yes Maria, the code should be executed on server.
Thank you steven I managed to publish on my wall finally
can you help in making publish possible from my app ?
Hi Tomee, You can just create a Iframe of your existing application and try it in Facebook App.
Steven what I would like to do is, anyone who uses my facebook app and clicks on a link to be able to publish on his own wall a message like “come and play this” or that game
I was looking on the facebook dev forums but it’s a mess majority of the examples are using deprecated functions, and no working example can be found
disappointing
Tomee, To Publish on Users you need to first generate a one time session key and later they need to give authentication, so that you can publish on their wall.
Hi,
i’m enchanted … wow , your article “5 Steps to publish on a facebook wall using php” is the unique resurce that explane how to publish on Facebook wall without use form login.
I googled a lot and fortunately i found your blog.
But i’m also curious,so i would ask you :
1. How did you find this solution? and all the links used to open a session? On developer Facebook section i could not find nothing about. Are maybe secret links ? ![]()
2. And, is possible to publish on a Fan-page wall instead of User wall ? If yes, how can i customize it?
Thanks a lot.
Bye from Italy
Fabio
Hi Fabio,
Even I too have to do some research like you when I got requirement to publish on a wall and I tried a lot at last I was successful to publish on wall. So I thought, since there are no post that truly describes how to publish on a wall. So I have to write this post. The solution is in facebook but not on a single page you need to read some 20- 40 pages and try lot of examples then you will get.
Yes, you can publish on Fan-page too, but you need to get permissions of that page too.
- Steven
Good…i have permission…i’m administrator of the Fan Page.
Can you give me some php code suggestion?
Hi Fabio,
Here is the example PHP code and the screenshots in my next post to publish on a Facebook fan’s page.
http://blog.theunical.com/facebook-integration/simple-steps-to-publish-on-facebook-fan-page-using-php/
If you still have any difficulties we can develop any facebook applications for you.
-Steven
Hello Steven Robert,
Thanks for reply, thanks for write such page to helps other.
Perhaps i was wrong some where now i can post without log in.
Will you please tell me how to add image /url along with the post and what are the purpose of this line ?
“‘query’ => “select uid2 from friend where uid1={$user}”));”
is this related to our table or FB’s table.
Thank you in advance and waiting for your reply.
I was late to write this because i could not test the application after your message.
Today i did .
Regards,
SHyam
Hi Shyam, That is a facebook table.
In my next post see how to publish images and videos to facebook is done
http://blog.theunical.com/facebook…/add-picture-on-facebook-wall-using-php/
http://blog.theunical.com/facebook…/post-video-on-facebook-wall-using-php/
Hello Steven ,
I am very pleased to see your reply and next blog for video and photo.
Thanks for all of them.
Steven i have one more query—-
can i sync the wall post to my twitter account ? Mean can i directly link these posting as a twitter tweet.
I will be very thankful for your reply.
Regards,
SHyam
Just thanks for all your articles about Facebok conection from PHP. Great resource and nice job.
Steven, I tried all of your code for step 3, and I cannot get it to work …. grrrrrr!!! I download the php library from facebook to my server. I copy the generatesession.key.php to the same directory on my server and name it index.php. Then I try to call my application from Facebook, but I get error message. What am I doing wrong?
Hi Maria,
Did you created the facebook application, as I described in Step1? Iam able to publish with a new account in 10 mins. May be you are doing something incorrect.
Also please make sure that you enter any working URL in Canvas call back URL and Connect URL. if this is missing then the application will not work.
I have 2 questions as below:
1. What is the real purpose of fetching friend list on your code, since I didn’t see any relation with it main topics; to put something on our wall.
2. Is there something that need to change from your code if I want to implement it on my mobile web ?
Thx 4 sharing..
Thank you! After many days of search, google’ing and testing this page was the key to posting messages to an offline user
Rangga, this code work’s perfect on mobile web too.
genius you save my week work, the documentation of facebook is a bullshit and you explain us so clear and concise.
Thank you very much.
Fede from rosario,argentina.
Success.!!!!!!!!!!!!!!11
Thank you so much for this code. I have been reading the facebook wiki for days trying to achieve this and they’ve managed to confuse me beyond belief. I was able to connect thanks to you!
I do have one question though, is the one-time code a link between the application and the facebook account? If I give my users the ability to post on their walls from my website can I use the token (assuming I save it somewhere and get their permission) indefinitely? I’m trying to figure out if the session key will expire.
Thanks again!
Sebastien , do you want to post users on your wall. If so, you can create a simple app and give to your users. If the users has to post on their own wall then you can simply use any bookmarking tool like Shareit, Addit etc.
I am stuck on step 3. I am assignning the apikey, secret and token, but when i run it i am not receiving the session key.
Hi Thank you for the code and description. The steps and code work like charm. I am successful implementing this but just wanted to know if there is a way to ask user ib a popup if they want to publish or skip.
Thank you a tons,
Kapil
Ohh i am so stupid ))) Thx it worked. this method is great!!
thanks for this article
you save my day…man, facebook framework is quite pain in the neck…hehehe
hi Steven
I have write message on my application wall
Your coding is used to message display on user wall
have u help me …??
thanks in advance
Great tutorial but I have one question. What if want to make not temporary session key but something to call stream.publish in background(for example as a cron job). In such scenario I can’t ask user for session key so I need some kind of persistent session key. How can I obtain it?
hello TheTester, Do u want to publish on user own wall, if yes then there in no need of any session key, you can just any bookmarking tool for this, like I used one in this blog.
This is GREAT… after wasting hours on <> Facebook API docs, I got this working in less than 5 minutes.
Like “TheTester”, I will be using this on a Cron Job to publish on my own wall… I have same concerns for “how long will the session key be valid?”… But I guess I will have to monitor “invalid session key” publishing errors and then generate a new session key…
Hi Faro, The session key will be valid until something unusual happens, Like if you hit facebook continuously , like in 1min you tried to hit some 50 times then that key will be invalid then you need to generate again a new key. If not then it will be valid for a longer time.
Hey!, when i try 2 and 3 steps, i get this error:
Canvas Callback URL must point to a directory (i.e., end with a “/”) or a dynamic page (i.e., have a “?” somewhere).
Connect URL must point to a directory (i.e., end with a “/”) or a dynamic page (i.e., have a “?” somewhere).
do you know why appears the error? and… can you help me to solve it?
Hi Abrahan, This Canvas URL and connect URL should be a publicly accessible URL.
Hi Steven,
I have follow all five steps
I have done with Publish to wall functionality.
Post has also display on users wall
But I am missing result means attachment object text, href,image and media on publish poppup….
I am used Asp.net MVC Framwork 2.0
Net Facebook API Client.
and in my old application Publish to wall functionality not working bcz of Facebook stop supporting to fb.connect.confirmDialog…method.
Please help me
its a very nice post, but i am unable to get 100% out of it. Can you let me know where the code generated by user as permanent code for my site need to be used.
each time after the permission if try to publish i get the below error.
‘Session key invalid or no longer valid’
please guide me where i am doing the wrong implementation
any kind of fast help will be very thankful
regards
navjot
Hi Navjot, After you execute Step3: Generate one time session key , on your browser you can see a session key printed. This is what the Permanent session key. This key will be in two parts separated by a hi-fen. Let me know if you still have any issues.
Hi Steven,
Pls help me
Dinesh The URL need to be Public Available URL and not a local URL, Check it once. Are you trying with a public URL?
This code works fine in posting to my profile’s wall.
If I setup a facebook page (http://www.facebook.com/pages/create.php), that page will have its own wall.
What do I need to change on these steps to post to that page’s wall?
First of all thanks for this tutorial.
I have one question:
I’ve made all the steps and its all working but.
My facebook name is:
Bruno Gomes
http://www.facebook.com/bmag2009
My Application name is
Creative-mood
http://www.facebook.com/apps/application.php?id=356981166204&ref=nf
My Fan page is:
bmag-01
http://www.facebook.com/pages/bmag-01/335140057869
When i run the script to publish to wall or the the fan page wall all goes well but it says:
Bruno Gomes From My App: publish steven on facebook
3 minutes ago via creative-mood · Comment · Like
And i wanted to say:
Creative-mood From My App: publish steven on facebook
3 minutes ago via creative-mood · Comment · Like
Is there any chance to do that.
I wanted to be the application creative-mood to make the post not myself..
Sorry for my english:
Thanks in advance
Hi Steven
I went through all 5 steps n used the code. Guess what it worked very smoothly
The only issue is it works only on my profile. my friend who is also using the application is not getting any messages on the Wall. Do u have any idea y?
hi Steven
I did everything as per the post and it worked on my id. but if anybody other than me tries it using their id it does not post the messages on the wall. could u please explain how do i achieve this.
Hi Sylvester Faro, Just get the pageid or fan page id or where ever you want to publish get that ID and set that in target id
Hello Chandan, This will be published on your wall and not their wall because you can set everything from your User, and given permission to your wall.
Hi Bruno, Hope this helps
http://tech.karolzielinski.com/publish-post-of-facebook-page-wall-as-a-page-not-a-user-python-facebook-rest-api
Thanks Steven for the fast reply.
I Dont know python
so i problably give up.
Thanks..
Hi Steven. Nice post! When I run the code to generate the session key, I get a “Notice: Uninitialized string offset: 0″. I have no idea why this appears. And also, I don’t get any value back from call_method ? Why is that ?
Tippi Try this code http://blog.theunical.com/wp-content/uploads/2010/01/fb_app.zip
Ok Bruno I will write up a post for you.
Great tutorial, thanks steven!
I have gotten all the way to Step 5, where it’s time to make my first wall post. Unfortunately the following error message appears:
post on wallexception ‘FacebookRestClientException’ with message ‘This method call must be signed with the application secret (You are probably calling a secure method using a session secret)’
Can anybody provide insight? I have verified application URLs specified, permissions granted, session key obtained, etc. Baffling. Please note that I am not very proficient in PHP I just managed to copy enough code to get it working up to step 5…
Hi Steven!
as Bruno, I need to publish post on Facebook Page wall as a Page (not a user).
Let me know when you will post the solution!!
Thank you
hi ,
i am unable to generate the permanent session key i have followed all the steps but somhow whn i tried executing step 3 .. it does not generate a session key can u please tell me what is going wrong ?
am eagrly awating your reply
thanxz
Sammy, what’s the error that you are getting?
Hello Bruno and Luca,
I was little busy this week, I was in Sun Tech Days 2010, at last, here is the post that helps you to publish on fan page as fan user using php, Let me know if you have still any issues. http://blog.theunical.com/facebook-integration/publish-on-facebook-fan-page-as-fan-user-using-php/
Hi Steven,
I could not post on the wall despite following the steps given on the blog. Please help. I am using the one time session key which is generated using the token code. Also , please let me know, how will the other users who are using my app will be able to post on their walls so that their frnds will get updates ?
Saurabh, check all the steps and all the fields of screen shots again. It will work. Other users need to give permission to their wall or Use some bookmarking tools, so that they can publish on their walls.
This code is good
require_once ( ‘php / facebook.php’), / / the two folders you have downloaded it mounted the server
$ api_key = “xxxxxxxxxxxxxxxxxxxxxxxxxx”;
$ secret_key = “xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx”;
$ facebook = new Facebook ($ api_key, $ secret_key);
$ user = $ facebook-> require_login ();
$ message = ‘news http://www.mega.cl test’;
$ has_permission = $ facebook-> api_client-> users_hasAppPermission (publish_stream “);
/ / The user must give permission for your application publishes information on its wall.
if ($ has_permission)
(
$ facebook-> api_client-> stream_publish ($ message);
echo ‘posted the message’. $ message;
)
else (
$ address = “http://www.facebook.com/connect/prompt_permissions.php?api_key =”. $ api_key. “& v = 1.0 & next = http://www.facebook.com/connect/login_success.html?xxRESULTTOKENxx&display = popup & ext_perm = read_stream, publish_stream & enable_profile_selector = 1 & profile_selector_ids = “. $ user;
header ( “location: $ address”);
)
?>
dear steven
i have already follow the instruction but i get error
can you help me ?
i just need the simple code
1. Status Update
so when ppl use the aplication it would like :
Name : i’m so busy
posted from mysite
Mirza, What’s the error you got?
Thank you so much,
I spent so long trying to do it,
and I could not have done this without this great guide.
oh ye and there was a small bug i found:
on step 3 this line is wrong:
$fb = new FacebookRestClient(FB_APIKEY, FB_SECRET);
and should be change to (since this parameters are not defined):
$fb = new FacebookRestClient($FB_APIKEY, $FB_SECRET);
hie steven ,
Your above 5 steps are really helpfull for me thanks a lot !…..
Now i want to display the images on Tab i have also mention the tab name and tab URL still it is not showing the content ..please help me…..
Regards,
Sunetra
Hi Sunetra, which method you used to post on tabs?
hello steven ,
im using static FBML ..can we use iframe tags in Tab Canvas…..
eg i have created my tab ” demophoto” and i want to display my data into the ” demophoto” i can use iframe ?
Sunetra, You can use FBML. Need to check which is used to post on tabs.
Thanks a lot. At first I found it confusing, (I’m new to facebook dev) but I got the hang of it. Extremely helpful
Steve, I thank you so much!
hi steve nice tutorial,
i just have a small problem.
i was on step four and when i replaced the values with my API KEYS this is what i get:
API Error Code: 100
API Error Description: Invalid parameter
Error Message: Param fbconnect must be a boolean
Please please help me.
What am i doing wrong?
this is the one that i should be replacing right?
–> APIKEYXxxxxxxxxxxxxxxxxx
please guide me, im almost there but not quite. thanks in advance
Steve – great tutorial and I thank you for the time and detail you put into it. I am having trouble with step #3 generating the session key. I downloaded your script generatesession.key.php put in my api key and secret but get the following error when executing:
Fatal error: Uncaught exception ‘FacebookRestClientException’ with message ‘Invalid parameter’ in /web/sites/widgets/facebook/facebook-platform/facebook-platform/php/facebookapi_php5_restlib.php:3025
Any advice is greatly appreciated.
I’m developing mobile web application (xHTML) in PHP which already success connected to fb.
But I still confuse for asked permission (Step 4 on your guide above) in mobile way.
Do you know how to adopt your Step #4 above to be run on mobile micro browser?
Thx in advance.
Rio You can execute Step4 in mobile version too
Darrasin try the other link I updated in post for Step3.
Love the blog. Step 4 failed with error fbconnect must be boolean. Replacing true with 1 seems to work.
steve, u skipped my question ![]()
help please. thanx
Yes BKC it seems facebook changed its api for true/false to 1/0.
Yes Uber,
replace true with number 1 and try.
Hi Steven, do you have any idea how to post the message on the wall of a fan page?
Felix, Check this post http://blog.theunical.com/facebook-integration/publish-on-facebook-fan-page-as-fan-user-using-php/ to Publish on Facebook Fan Page as fan user
hi steven
very nice post thanks man. I am facing one issue.
I want is abuot creating avatar and people can come and like or dislike any avatar. even this avatar is created by a friend or not.
now i want my app to publish on person A wall, if person B comes and like his/her avatar in the app & both are not even friends.
Both person A and B have given exntended permission to the app also and are not friend.
I am using following publish stream code
$facebook->api_client->stream_publish($message,null,null,$personA_id,$app_id)
Its showing this error
post on wallexception ‘FacebookRestClientException’ with message ‘The user hasn’t authorized the application to perform this action’ in /home/jill/web/php/facebook-platform/php/facebookapi_php5_restlib.php:3374 Stack trace: #0 /home/jill/web/php/facebook-platform/php/facebookapi_php5_restlib.php(932): FacebookRestClient->call_method(’facebook.stream…’, Array) #1 /home/jill/web/public/samsung/style-n-win-dev/insert-services2.php(54): FacebookRestClient->stream_publish(’From My App: pu…’, NULL, NULL, ‘100000845001406′, ‘109444382410730′) #2 {main}
but if I use following code which person B comes and likes his own avatar it works and publish post on the wall without error.
$facebook->api_client->stream_publish($message,null,null,$personB_id,$app_id)
please can you guide me where i am doing mistake.
thanks a lot
Aarif, It could be the Permission issue from Step4, check once
hi sir..
i can’t download facebook library..
the link above gave me error not found ..
am i wrong?…
thx
ive download from http://github.com/facebook/php-sdk
but after run the code, i got this error,
Fatal error: Call to undefined method stdClass::admin_setAppProperties()
in my php code i’ve include
require_once ‘./facebook.php’; // it is the same path with my index.php
need a clue.
thx
Hi Dina,
Thanks for pointing that out, I have updated the link now. Facebook has changed that URL.
thx sir,
it’s works
Hi,
I run the test code and got the following error:
Fatal error: Call to undefined method Facebook::require_login() in /home/content/46/4899446/html/facebook/mytestapp/index.php on line 18
Any idea?
Steven does your library still works is everything ok? I performed all steps before and it worked but now i cant get to use the function from it. I have checked everything. When it comes for functions it stops.
Aziz,
Which function are u referring, Face book has changed some of the api settings.
I am using
$facebook->api_client->stream_publish();
$facebook->api_client->photos_upload();
$facebook->api_client->video_upload();
Aziz, Try download the library from above, facebook has changed its library. The methods you are using still work.
Hmm… when i used this tutorial from begining it worked fine again and I have checked all my previous codes, they worked too. strange.. though. Anyway thank you again and for the tutorial again. I just wonder if it is possible to do the same with new api
Hi Steven,
Thanx for such wonderful description, its pretty easy as we go step by step.
I was just wondering if my website can have ability to post on other user’s wall
thanx
Hi Nikhil, If the user gives permission to their wall then you can publish on their wall too.
Ya I understand that but don’t they require their API Key and all, an average user won’t even take little pain to get their Keys
What I need is that user could post on other person’s(friends ) wall.
Thanx for quick response
No Nikhil, Your API will be sufficient, They just need to give permission to their wall.
Hi i tried several times to do it but i get this error exception ‘FacebookRestClientException’ with message ‘Session key invalid or no longer valid etc..
Help!!
Hi Steven
Very nice post thanks man. I am facing one issue.
We can post the message to my Facebook wall, But the other user whole are using my app will cannot post message on their Facebook walls.
Help!!
Grace
can you give us the source code
require_login();
$fb = new FacebookRestClient(FB_APIKEY, FB_SECRET);
$facebook->api_client->session_key = $fb->do_get_session($fb->auth_createToken());
$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)));
/*if( $facebook->api_client->stream_publish($message))
echo “Added on FB Wall”;
} catch(Exception $e) {
echo $e . “”;*/
//}
//$message = ‘Check out this cute pic.’;
$attachment = array(
‘name’ => ‘i\’m bursting with joy’,
‘href’ => ‘http://icanhascheezburger.com/2009/04/22/funny-pictures-bursting-with-joy/’,
‘caption’ => ‘{*actor*} rated the lolcat 5 stars’,
‘description’ => ‘a funny looking cat’,
‘properties’ => array(’category’ => array(
‘text’ => ‘humor’,
‘href’ => ‘http://www.icanhascheezburger.com/category/humor’),
‘ratings’ => ‘5 stars’),
‘media’ => array(array(’type’ => ‘image’,
’src’ => ‘http://icanhascheezburger.files.wordpress.com/2009/03/funny-pictures-your-cat-is-bursting-with-joy1.jpg’,
‘href’ => ‘http://icanhascheezburger.com/2009/04/22/funny-pictures-bursting-with-joy/’)),
‘latitude’ => ‘41.4′, //Let’s add some custom metadata in the form of key/value pairs
‘longitude’ => ‘2.19′);
$action_links = array(
array(’text’ => ‘Recaption this’,
‘href’ => ‘http://mine.icanhascheezburger.com/default.aspx?tiid=1192742&recap=1#step2′));
$attachment = json_encode($attachment);
$action_links = json_encode($action_links);
if($facebook->api_client->stream_publish($message)){
echo “Added on FB Wall”;
}else{
echo “FB Wall failed”;
}
} catch(Exception $e){
echo $e . “”;
}
?>
Hi,
I am trying to develop a project using facebook -java-api.
Here I want to extract the face book data and store them in a data base using the facebook-java-api. But I am new for this field.
I connected to the facebook developers page and created a new application. Now I need to know how to get the face book data like friend list/ profile picture etc. and where to place these codes I’m going to write.
If you can help me it is really appreciated.
Thank you!
its great man thanx a lot/////////
i was working with facebook app development and searched a lot in developer wiki but couldn’t find that… great great post
hi steven
Its very nice post thanks, I am facing one issue.
At Step2: Generate One Time Token to generate Session key ::
We have many users in my site.so as per your coding how can we generate One time Token using php code for different logins.
Please help us !!!!!!!
I follow the steps until 5. i got one time token and session. Now I run in localhost, then it shows the error as below: post on wallexception ‘FacebookRestClientException’ with message ‘Session key invalid or no longer valid’ in /var/www/anulya/facebook-platform/php/facebookapi_php5_restlib.php:3025 Stack trace: #0 /var/www/anulya/facebook-platform/php/facebookapi_php5_restlib.php(2882): FacebookRestClient->call_method(’facebook.admin….’, Array) #1 /var/www/anulya/facebook-platform/test.php(33): FacebookRestClient->admin_setAppProperties(Array) #2 {main}
Any help Please Thank you
Hi to all,
I have created th facebook application and i set the all permission for user to access. I want to get the session key for every user dynamically… by using this url http://www.facebook.com/code_gen.php?v=1.0&api_key=YOUR_API_KEY we cant get it dynamically… we can get by manually…. A thing is that, One user will come to my site, while he login i want to store all his information in DB with seesion key for offline access…. Another user ll.. as usually want to get… Please help to get it… very urgent…
I am starting the connection with this url http://m.facebook.com/authorize.php?api_key=YOUR_API_KEY&v=1.0&ext_perm=offline_access
if this url returns session key it ll be appreciated…
thanks
saran
http://careerjobz.com
Hi steven,
Thank you for your reply in few hours ago. Yet i still can find any solution for my problem.
When i open the page. It only echoed post on wall. No great wall appear. You may check it out here. http://h3llst0rm.phpnet.us/upd/haha.php
Hope you help me to sort this out. Thx
Hi Steven!
thank you very much for yours articles!
I would only know if it’s possible to add “Friend tags” or “Page tags” in stream_publish (using FBML libraries).
( Es.: “@[ID:4387]” -> “John” prefer pasta to pizza )
bye
Hi,
I don’t undersantd why, but Step 4 never show me 3 screens.
I only got “success” displayed.
You told :
‘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.’
Can you give more explain please, my facebook application is running and everything seem good in definition of application.
Note: I want to post messages on my wall thrue application in batch mode, not in browser context.
Thanks for your reply
@piv64, you can do batch updates, the back URL or Canvas URL will be there in facebook setting page,
@Junior, you can add tags too
Hi,
In fact, even if nothing else than ’success’ is displayed, configuration for write autorization on my facebook wall is good.
Important:
I saw a solution on application parameters in way to diagnose publish problems.
If application is defined as ‘desktop’, everything run and many obscured problem related to stream_publish are solved.
I think that lots of people are interested by this.
An other problem, is there a solution to send message with accent (french text) and what’s the solution for message encoding ?
Thank for your reply.
Hi Steven,
I thank you for the quick response!
I’m trying with this simple code but don’t work:
$message = ‘This message is sent by ‘;
The problem is that facebook does not view tags and show the string as it is…
see ‘ya
@Junior here is how you add tags to your post http://blog.theunical.com/facebook-integration/facebook-api-how-to-add-tags-to-post-api-using-php/
Hi Steven,
I tried but the script does not work as I want … maybe I have not explained well …
When I post a new message on my wall I would like the tagged user display a message in its notifications like “Junior have tagged you in a post.”
Currently, when I insert the tag as you suggested is not sent any notification to the recipient but only shows a link.
How can I do?
@Junior yes its just a link tag
please add a lesson for sending images to facebook wall in actual sizes
Thanks for the tut, i tried all the steps and it worked but i would like to use this link… https://graph.facebook.com/oauth/authorize?client_id=xxx&redirect_uri=http://apps.facebook.com/xxxx/&scope=publish_stream … in step 3.. i used the SESSIONKEY that was given to my profile and it worked… but how can i obtain the sessionkey that each user gets after granting the app permission? any way to grab theirs? i only want to post on their feeds/wall when they are online… i still don’t understand how to get each user’s sessionkey and send a post on each one of them. Thanks for any help
Hi Steven,
it’s possible to publish a message on the wall of the friends of the app/funpage?
Ex.:
1. User visit my site
2. The user publish a message on my site
3. My site publish this message on the facebook wall of the User
how do I write permissions?
Same question as Junior.
is there any script by which i can use user’s facebook login details, and can post something on user’s wall, as this can be done for twitter using cURL lib of php
thanks in advice ….
Hi,
I want to run a continuous fb wall posting from my cakephp code, Is there any way of doing the same, without generating this one time session key?
If yes, earliest reply would be appreciated!
JOI
@Joomla its mandate to generate the key
@Steven, thanks for your time and reply. Yes session key generation is must, but Is there a way; via my php script, it can generate automatic session and then post some message to users wall?
I am running another code, for twitter, into which tweeting message, which is working perfect as needed from our project source code, but for facebook I am not able to find much useful info, so would be appreciated, if you can help somehow to get facebook wall posting working from my website script dynamically/automatically !
Thanks in advance!
I’m getting the following error when trying to run the code. I actually tried combining the snippets into 1 page and this is what I got. Any ideas?
Fatal error: Uncaught exception ‘FacebookRestClientException’ with message ‘Invalid parameter’ in /home/webdad3/public_html/AlphaProject/library/facebook-platform/php/facebookapi_php5_restlib.php:3025 Stack trace: #0 /home/webdad3/public_html/AlphaProject/webservice/ws_facebookPublishing.php(14): FacebookRestClient->call_method(’facebook.auth.g…’, Array) #1 {main} thrown in /home/webdad3/public_html/AlphaProject/library/facebook-platform/php/facebookapi_php5_restlib.php on line 3025
Ignore my comment. I got it to work. The tutorial does what it says it does
@ Jeff you can’t combine all the steps in one page, you need to do it seperatly
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.
@ Jeff
hello Jeff, you can try to find something useful for you at below link:
http://wiki.developers.facebook.com/index.php/Stream.publish
They have specially mention “A developer of the application must edit the application profile page’s Wall Settings (Edit Application > Edit) and verify under Posting Ability that Fans can write or post content on the wall is checked.”, so I am thinking its for you, which you’re finding!
Cheers!
Tell me what you're thinking...
and oh, if you want a pic to show with your comment, go get a gravatar!






