Publish on Facebook Fan Page as fan user Using PHP
First Follow all the steps to give permissions to publish on Facebook. http://blog.theunical.com/facebook-integration/5-steps-to-publish-on-a-facebook-wall-using-php/
Add FaceBook application to your fan page
Just Go to http://www.facebook.com/apps/application.php?id=ID_OF_YOUR_APP.
Find link ‘Add to my Page’ on the left, click on it. Find your page on the list and click on ‘Add to page’ next to this page.
Set Your Application type as WEB
Go to http://www.facebook.com/developers/editapp.php?app_id=ID_OF_YOUR_APP.
Choose ‘Web’ next to ‘Application type’ and click on ‘Save Changes’ button.
Add permissions to your app
Prepare special link:
replace YOUR_API_KEY for an API KEY of your application and ID_OF_YOUR_PAGE for an id of your page
Run this URL in your web browser. Click on ‘Allow’. This will set the permissions to your application to publish on page.
You should see a message: ‘Success’ message.
Check Permissions
Go to http://developers.facebook.com/tools.php?app_id=ID_OF_YOUR_PAGE and check your permissions.
Choose your application, change ‘Response Format’ to JSON, choose method ‘users.hasAppPermission’, fill publish_stream in ext_perm and id of your page in uid.
You should see result: 1.
That means that everything is ok. If the result is 0. then something went wrong. Then check all the above steps again.
Code To Publish on Fan Page as Fan User Using PHP
Then to publish on fan page as a Fan page user and not the facebook user just follow below code.
For this you need to get Fan page ID:
Example : http://www.facebook.com/pages/Fan-Page/xxxxxxx
where xxxxxxx is the fan page id.
In Steam publish method just replace the $page_id with your above fan page id.
stream_publish($message, $attachment,$action_links, null,$page_id).
<?php
// FB_APIKEY is your facebook application api key
// FB_SECRET is your application secrete key
define('FB_APIKEY', 'YOUR_APIKEY');
define('FB_SECRET', 'YOUR_SECRET');
define('FB_SESSION', 'YOUR_SESSION_key');
require_once('facebook-platform/php/facebook.php');
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 Fan Page as Fan User';
$page_id ="xxxxxxxxxxx";
if( $facebook->api_client->stream_publish($message, $attachment,$action_links, null,$page_id))
echo "Added on FB Wall on Fan Page";
} catch(Exception $e) {
echo $e . "<br />";
}
?>
Below is the screen where you can see the message published are fan user.

– Steven
Follow Us
Comments
56 Comments on Publish on Facebook Fan Page as fan user Using PHP
-
Nick on
Thu, 25th Mar 2010 8:06 pm
-
Nick on
Thu, 25th Mar 2010 8:10 pm
-
Wang on
Fri, 26th Mar 2010 1:13 am
-
Steven Robert on
Fri, 26th Mar 2010 4:36 am
-
Wang on
Fri, 26th Mar 2010 5:48 am
-
Wang on
Fri, 26th Mar 2010 6:06 am
-
Steven Robert on
Fri, 26th Mar 2010 6:39 am
-
Luca on
Fri, 26th Mar 2010 7:41 am
-
Luca on
Fri, 26th Mar 2010 7:42 am
-
Steven Robert on
Fri, 26th Mar 2010 9:23 am
-
Steven Robert on
Fri, 26th Mar 2010 9:26 am
-
Luca on
Fri, 26th Mar 2010 10:05 am
-
Wang on
Fri, 26th Mar 2010 10:32 am
-
Luca on
Fri, 26th Mar 2010 11:13 am
-
Steven Robert on
Sat, 27th Mar 2010 6:36 am
-
Wang on
Mon, 29th Mar 2010 3:53 am
-
Wang on
Mon, 29th Mar 2010 3:58 am
-
Wang on
Mon, 29th Mar 2010 4:12 am
-
Wang on
Mon, 29th Mar 2010 7:12 am
-
Andreas on
Tue, 27th Apr 2010 6:32 pm
-
Sandra on
Wed, 12th May 2010 5:31 am
-
Bryan C. on
Mon, 24th May 2010 4:42 pm
-
#iranelection on
Fri, 11th Jun 2010 12:36 am
-
Doug A on
Thu, 17th Jun 2010 5:51 pm
-
Steven Robert on
Fri, 18th Jun 2010 12:09 am
-
Doug A on
Fri, 18th Jun 2010 2:20 pm
-
Sam Simpson on
Fri, 9th Jul 2010 10:35 pm
-
Sam Simpson on
Fri, 9th Jul 2010 10:37 pm
-
Sunil on
Thu, 15th Jul 2010 5:07 pm
-
Jeff on
Sat, 24th Jul 2010 10:31 am
-
Vrushali on
Mon, 1st Nov 2010 9:16 am
-
Steven Robert on
Mon, 1st Nov 2010 12:56 pm
-
Vrushali on
Tue, 2nd Nov 2010 12:49 am
-
dennis on
Tue, 16th Nov 2010 9:50 am
-
baljeet on
Sat, 27th Nov 2010 6:25 am
-
baljeet on
Sat, 27th Nov 2010 7:33 am
-
Steven Robert on
Sat, 27th Nov 2010 8:23 am
-
baljeet on
Sat, 27th Nov 2010 1:06 pm
-
Steven Robert on
Sat, 27th Nov 2010 11:01 pm
-
baljeet on
Sun, 28th Nov 2010 2:33 am
-
Alexia Nessel on
Sun, 28th Nov 2010 2:59 pm
-
baljeet on
Mon, 29th Nov 2010 3:26 am
-
baljeet on
Mon, 29th Nov 2010 3:40 am
-
baljeet on
Wed, 1st Dec 2010 1:13 am
-
jay on
Wed, 15th Dec 2010 1:22 pm
-
baljeet on
Wed, 5th Jan 2011 8:30 am
-
baljeet on
Mon, 24th Jan 2011 12:41 pm
-
5 Steps to publish on a facebook wall using php | TheUnical Technologies Blog on
Sun, 13th Mar 2011 2:58 am
-
Hetal on
Wed, 29th Jun 2011 6:26 pm
-
Vishal on
Fri, 5th Aug 2011 1:20 pm
-
jan on
Tue, 10th Jan 2012 4:35 pm
-
john on
Wed, 7th Mar 2012 12:48 pm
-
Candy on
Wed, 9th May 2012 3:17 am
-
Sotheayuth on
Fri, 18th May 2012 4:38 pm
-
Sotheayuth on
Fri, 18th May 2012 9:15 pm
-
Marios on
Wed, 1st Aug 2012 8:33 am
Yeah, unfortunately I am still having the same error message. As with the other example. I’m ready to pull my hair out and wish I could punch the Facebook API in the face LOL. Integrating with Twitter was 1000x easier.
Message still says:
exception ‘FacebookRestClientException’ with message ‘This method call must be signed with the application secret (You are probably calling a secure method using a session secret)’
I have my app defined as a “Desktop” app. Should it be defined otherwise? Any insight would be greatly appreciated…
Sorry Steven don’t mean to be spamming your board – But alas I answered my own question. I changed my app from being defined as “Desktop” to “Web” and sure enough it worked!
Thanks again for your helpful articles and I hope this info helps anybody else encountering this challenge…
Hi Steven, I followed your previous post and I did post to my profile’s wall successful. But when I try to post to my page’s wall, I got an error :
exception ‘FacebookRestClientException’ with message ‘User not visible’
if I run: $facebook->api_client->stream_publish($message, NULL, NULL,$page_id)
(call stream_publish with 4 params like FB’s documentation)
and this error:
exception ‘FacebookRestClientException’ with message ‘The user hasn’t authorized the application to perform this action’
if I run: $facebook->api_client->stream_publish($message, NULL, NULL, NULL, $page_id)
(call stream_publish with 5 params like your instructions)
Notice that I already checked to ‘Facebook Pages’ on Authentication settings of Application and added my app to my page.
Can you help me to solve this problem. Thanks in advance.
Wang, Pls use the below URL to set the permissions to your fan page.
http://www.facebook.com/connect/prompt_permissions.php?api_key=YOUR_API_KEY&v=1.0&next=http://www.facebook.com/connect/login_success.html?xxRESULTTOKENxx&display=page&ext_perm=publish_stream,offline_access&enable_profile_selector=1&profile_selector_ids=ID_OF_YOUR_PAGE
replace YOUR_API_KEY for an API KEY of your application and ID_OF_YOUR_PAGE for an id of your page
Run this URL in your web browser. Click on ‘Allow’.
You should see a message: ‘Success’.
Hi Steven, thanks for your very quick answer. But I did as you said, message Success did show up, but I still got the message:
‘The user hasn’t authorized the application to perform this action’.
I tested my code again to publish message on profile’s wall, it still works good. I really dont know why it cant work on my page. Is there any other ways that I can try ?
Thanks for your help again.
About my problem, I look around on internet and I found this page:
http://thinkdiff.net/facebook/update-facebook-page-status-automatically/
The author said that we need ‘extended permission’ by running the permission.php (code posted on this site), but I dont know how to run that file on Facebook (http://apps.facebook.com/yourapps/permission.php !? )
In case you have other solutions for me, if not, can you look at that page to check if it is a solution for my problem ? Thanks you.
Wang, for the below URL did you given your fan page id ?
http://www.facebook.com/connect/prompt_permissions.php?api_key=YOUR_API_KEY&v=1.0&next=http://www.facebook.com/connect/login_success.html?xxRESULTTOKENxx&display=page&ext_perm=publish_stream,offline_access&enable_profile_selector=1&profile_selector_ids=ID_OF_YOUR_PAGE
Hi,
it doesn’t work for me.
I receive the error ” 1Object id #4 ”
Thank you!
Luca
And, this is the page
http://www.facebook.com/apps/application.php?id=102552236449810
Hi Luca,
There is some permission problems in your application. Your application returns 0 and not 1.
Go to http://developers.facebook.com/tools.php?app_id=335851346097 and check your permissions.
Choose your application, change ‘Response Format’ to JSON, choose method ‘users.hasAppPermission’, fill publish_stream in ext_perm and id of your page in uid.
You should see result: 1.
That means that everything is ok.
Luca Your application is set to desktop set it to Web
Go to http://www.facebook.com/developers/editapp.php?app_id=ID_OF_YOUR_APP.
Choose ‘Web’ next to ‘Application type’ and click on ‘Save Changes’ button
Hi Steven,
application is set to web..
When I look at permissions I receive:
{“error_code”:200,”error_msg”:”User must have accepted TOS”,….
What I should do to sort it out?
Thanks!!!
Yes, I did ,Steven. And I got Success message too.
using my apps YOUR_API_KEY and my apps id 102552236449810, I receive a Success
Luca,
I created one more fan page and it works for me. check all the steps again.
http://www.facebook.com/pages/Publish-fan-test/105557559477382?v=wall
Hi Steven, I tried many times but still got message ‘The user hasn’t authorized the application to perform this action’. When the first time I follow you 5 steps to publish on wall I got the same message too (because I didnt run the permission link yet). But this time I run your special link to set permission and I got the ‘Success’ message too, but still fail.
Do you know how to debug this situations ? Pls help. Thanks alot !
I tried even with my application’s wall and still got the same message. I use my app to post message on it’s wall but stil fail, I really can’t got it !
Sorry, I dont want to spam your post, but I just want you to know that I did check permission using Facebook tools and I’m sure that my app already has permission to post on my fan page’s wall.
Finally, with Steven’s help, we find out that my problem was because of the quotes. I pass the page_id to function stream_publish without quotes. Thanks Steven for your enthusiastic help.
Hi Steven,
very good work!
There is a small mistake in the link – this is the correct one
http://www.facebook.com/connect/prompt_permissions.php?api_key=MYAPIKEY&v=1.0&next=http://www.facebook.com/connect/login_success.html?xxRESULTTOKENxx&display=popup&ext_perm=publish_stream&enable_profile_selector=1&profile_selector_ids=THEPAGEID
found on
http://stackoverflow.com/questions/2097665/authorizing-a-facebook-fan-page-for-status-updates
Thank you for the nice post. i had the same problem like Wang but now it still works. nice.
I fixed the 100 error by removing the “,offline_access” element from the prompt permissions URL and it worked perfectly.
Thanks it worked for me
Steven – Great detailed post as usual! I have implemented your code and it’s all working fine except for one small important detail.
I am using this to post as an fan page admin to fan page and it works. However, the posting comes across with my personal account profile information, picture instead of that of the Fan page.
Is there a way to make the posting seem like its published by the Fan page itself?
Thanks and regards,
Doug
Yes Doug, Check your target id , it should be fan pageid
Yes – thank you Steven. But I am passing the page id of the fan page. It just shows that I’ve (my account) has added the post to the fan page instead of looking like it was the page itself that made the post.
I’m hoping that it’s just some type of permissions issue but I feel like I’ve tried all the urls here.
Thanks again!
I am getting this error and it is driving me nuts, I have been trying all the tutorials for 2 days straight and can’t get this to work. Please point me in the right direction
Fatal error: Call to undefined method stdClass::admin_setAppProperties()
I should also add that this step isn’t working for me, going to this url (http://developers.facebook.com/tools.php?app_id=ID_OF_YOUR_PAGE) with my page id just takes me to a test console for the javascript sdk
This site and the post http://stackoverflow.com/questions/2097665/authorizing-a-facebook-fan-page-for-status-updates was very helpful. Here is what additionally I did that worked:
Ok Steven I followed both of your tutorials and now I get the following message in Facebok anytime the code is called:
Jeff Vaccaro->GODSurfer:AlphaProject: From GODSurfer:AlphaProject:A story on GODSurfer.com was voted up!
4 minutes ago via GODSurfer:AlphaProject – App · Comment · LikeUnlike · Report
That is sort of what I want, however, I don’t always want it to be me. Does that make sense? Is there a way that instead of the message coming from me can I just do it from the application?
i.e.
GODSurfer App->GODSurfer:AlphaProject: message goes here…
Hi,
I have followed each step as mentioned above,
I have struck at step Check Permissions.
When I check the URL mentioned in “Add permissions to your app” step using page id, I get the success message (FB is not showing me allow /Deny box and directly showing me the success message)
I have created one time SessionId as given in last article (5 Steps to publish on a facebook wall using php)
I am able to post my message on my profile wall.
But when I am trying to do it on Page wall It is giving me the following error
“The user hasn’t authorized the application to perform this action”
You can check the error here;
http://folkehesten.devant.no/postonfbpage.php
Please let me know where I am going wrong.
Thanks in advance
Regards
-Vrushali
@Vrushali See my other post to post on a fan page. you need to set targetid
Hi Steven,
Thank you for quick reply.
I was doing same things yesterday but not got any luck.
When today I follow the same it start working.
I think Facebook is taking some time to update the settings.
Both your posts are amazing, that really helps me to solve the challenges.
One link I want to share for checking the permission, where I got confuse and finally found the following link..
http://developers.facebook.com/docs/reference/rest/users.hasAppPermission
Thanks again..
Regards
-Vrushali
I am php developer working on an application to publish posts on to a page [available to public]
I followed the steps to post a message as a page . I have set the target id to the page id
When i log into the face book account in which i own this page I can see the posts from my web application only when I click on ‘+ other’ tab under wall. Just and just others so not show.
Also when i friend [ not in my friend list /fan] searches for the page name in his account , the postings are not to be seen under any of the above mentioned 3 tabs . Could you please tell me how to make these posts from my application available to all those who visit the page.
Thanks
is there any way to automate the step :
Add FaceBook application to your fan page
in other words, can we show a popup of fan pages listing and redirect to our own site on success.
actually I dont want the user to click on the link on Facebook which says “add to my page”
I need to upload a photo/video on fan page wall. Functions are available in php rest lib for this: photos_upload() and video_upload() . I tried for photo but It was uploading the photo on my user page, NOT on fan page wall. Please advice.
Thanks
Baljeet
Baljeet, You can use the target id to publish on fan page.
Thanks Steve !
Thanks for quick response, Its working now. Have you written any article on how to do similar things on Twitter and LinkedIn ?
No Baljeet, I will try to prepare that post to for Twitter and LinkedIn
I’ll will wait for it, and will try at my end too.
I was trying to publish video on fan page wall using the upload videos function. But looks like it does not take page_id or target_id as parameter, then how to post a video on fan page.
Also for creating events, there is a function but it also does not seem taking page_id/target id as parameter. One of parameter here is an arrray, may be that contains all values.
Please suggest how to move ahead.
Thanks again
Baljeet
When I originally commented I clicked the “Notify me when new comments are added” checkbox and now each time a comment is added I get four emails with the same comment.
Hi Steve, right now, while adding the app to the fan page, I’m redirecting to the facebook site. On facebook site, user clicks on “add to may page”, which opens a popups and so on..
But user point of view it is not good. Is there any way to show this popup of my site itself or some iframe or something similar which is user friendly.
Thanks
Baljeet
In other words, is there any way to list all the pages for particular session id, and list them to select one or more, and add with the app
Hi Steve,
Sorry for posting similar question again, but i have got some progress in adding fan page to my facebook application. Now I’m able to display the fan pages I own on my site itself. I just need some script which will add selected pages to the application.
Thanks
Baljeet
people who able to post on their (user profile) wall, but can’t post on a fan page is because the sample above is not given a right target_id
original: if( $facebook->api_client->stream_publish($message, $attachment,$action_links, null,$page_id))
corrected: if( $facebook->api_client->stream_publish($message, $attachment,$action_links, $target_id[fan page id],$user_id))
[fan page id] by clicking the fan page, and you can see a number on the url.
[user_id] by clicking your name next to the profile photo then you can get it from url also. eg. http://www.facebook.com/#!/profile.php?id=xxxxxxxxx
i have sample on C# but not in PHP.
Hi Jay,
Thanks for sharing your views. I was trying the original code from Steve and it was working fine for me. I was posting to page wall as page admin. The NULL in original code indicates the default poster (page admin this case).
I tried ur code and it is working fine as well/
are you pointing towards change in the sequence of parameters (last two here) ?
Facebook is changing the design of fan pages. They are removing the boxes tabs. any clues how it will look like ?
[...] See here how to publish on facebook page as a facebook user [...]
It working awesome.
Thanks dude, this is what i want to know..
Hi Steven ,
I followed your article but some how it is failing at “$facebook->api_client->admin_setAppProperties” . Error message is something like [message:protected] => The session has been invalidated because the user has changed the password.
Session is active . Could you please give some thoughts here
i had no problems with the previous tutorial, allowing to post new items on my user stream. however, when i tried getting my page to do the same, i get an error when it comes to adding the permissions to my app. here’s the facebook error:
API Error Code: 100
API Error Description: Invalid parameter
Error Message: When enabling the profile selector, an app may not request permissions that do not apply to all profiles in the selector. Note: You are seeing this message because you are a developer of this application. For regular users, inapplicable permissions are silently ignored.
any ideas?
Hi, i can’t get the session key when requesting the permission, also when i am using http://www.facebook.com/connect/prompt_permissions.php?api_key=YOUR_API_KEY&v=1.0&next=http://www.facebook.com/connect/login_success.html?xxRESULTTOKENxx&display=page&ext_perm=publish_stream,offline_access&enable_profile_selector=1&profile_selector_ids=ID_OF_YOUR_PAGE to get the permission it’s giving me an error so i removed the offline access but i didn’t get any session key to put it in the code.
can any body advise ???
Hi,
I followed the tutorial above yet, I got stucked on setting the permission of my fan page. I got this error message:
ERROR: This endpoint has been deprecated. To temporarily reenable it, you may disable the “august_2012″ platform migration. It will be disabled permanently on August 1, 2012.
Can you helpe me solving this issue?
Thanks
Candy,
The following can resolve your issue:
– Goto your application
– Under the left tab Setting > Advance
– Under the block “Migrations”, set the “auguest_2012″ from “Enabled” to “Disabled”.
If you still face other problem, please let me know,
Sotheayuth,
http://www.khmnews.com
Hi Steven,
After working hard trying for the whole night without sleep. I can manage to publish my Article to facebook automatically.
But it seems not fit to the need! I think every who succeed with the plug feel in the same ways!
There are 2 issues, I would ask for your assistant below:
#1 – CASE I manage to publish to my OWN PROFILE – It will display both title and attachment.
– When other user click on my link, that user has to grant permission for my application first.
– It is not allowed me to handle the on click target windows. Simply, every external links in facebook are opened in new windows (_blank). But in this case, it opens the current windows for me which makes me lose the facebook page.
#2 – CASE I mange to publish to FAN PAGE – If i do not add the attachment parameter, I will get the post as admin of the fan page. Otherwise, I publish with attachment. It will display as the post which is acted by me in the fan page. It is not professional!
Remark: I found that the plug in “Auto FBook” in this link can resolve the issue #2 http://www.stilero.com/downloads/joomla-plugins/joomla-autofbook.html
However I do not know how to do that!!!
Is there any solution to satisfy the need that I and some people need?
Best Regards,
Sotheayuth,
http://www.khmnews.com
Hello,
Please explain how to do it as releasing attachment, to publish the name of the page, not on behalf of the admin page?
Thank you!
Tell me what you're thinking...
and oh, if you want a pic to show with your comment, go get a gravatar!





