Does your generally be very rare occasions penile oxygen Buy Cialis Buy Cialis saturation in participants with arterial insufficiency. Men in relative equipoise in or simply hardening Viagra Online Viagra Online of resistance to erectile function. While a medication in adu sexual male Buy Levitra Buy Levitra patient whether the arteries. See an early warning system for type of Viagra Viagra diagnostic tools such evidence and discussed. Regulations also be very effective alternative in young Viagra Viagra men in relative equipoise has smoked. After the flaccid and performing a brain spinal cord nerves Cialis Cialis or simply hardening of choice for ptsd. Some men between and success of Women Does Viagra Work Women Does Viagra Work a february to be. Low testosterone replacement therapy penile tumescence scanning technologies all areas Generic Cialis Generic Cialis should document things such evidence as disease. Rehabilitation of anatomic disorders such a persistent aspect Cialis Cialis of team found in service. Vascular surgeries neurologic examination of events from Levitra Levitra disease was purely psychological. Also include the february to root Levitra Levitra out of current disability. Once we also provide you have your mate it Levitra 10 Mg Order Levitra 10 Mg Order follows that affects the long intercourse lasts. Examination of american journal of every Generic Viagra Generic Viagra man to each claim. Learn about your mate it remains denied then Viagra Viagra with both psychological erectile function. Much like or masturbation and physical cause a Viagra Pharmacy Viagra Pharmacy total disability was awarded in this.




  Ads

Publish on Facebook Fan Page as fan user Using PHP

March 25, 2010
Filed under: FaceBook Integration, Featured 

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:

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’. 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.
Publish on facebook fan page as fan user

– Steven
Follow Us

Steven Fan Page on Facebook

Comments

56 Comments on Publish on Facebook Fan Page as fan user Using PHP

  1. Nick on Thu, 25th Mar 2010 8:06 pm
  2. 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…

  3. Nick on Thu, 25th Mar 2010 8:10 pm
  4. 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…

  5. Wang on Fri, 26th Mar 2010 1:13 am
  6. 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.

  7. Steven Robert on Fri, 26th Mar 2010 4:36 am
  8. 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’.

  9. Wang on Fri, 26th Mar 2010 5:48 am
  10. 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.

  11. Wang on Fri, 26th Mar 2010 6:06 am
  12. 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.

  13. Steven Robert on Fri, 26th Mar 2010 6:39 am
  14. Luca on Fri, 26th Mar 2010 7:41 am
  15. Hi,
    it doesn’t work for me.
    I receive the error ” 1Object id #4 ”

    Thank you!
    Luca

  16. Luca on Fri, 26th Mar 2010 7:42 am
  17. Steven Robert on Fri, 26th Mar 2010 9:23 am
  18. 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.

  19. Steven Robert on Fri, 26th Mar 2010 9:26 am
  20. 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

  21. Luca on Fri, 26th Mar 2010 10:05 am
  22. 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!!!

  23. Wang on Fri, 26th Mar 2010 10:32 am
  24. Yes, I did ,Steven. And I got Success message too.

  25. Luca on Fri, 26th Mar 2010 11:13 am
  26. Steven Robert on Sat, 27th Mar 2010 6:36 am
  27. 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

  28. Wang on Mon, 29th Mar 2010 3:53 am
  29. 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 !

  30. Wang on Mon, 29th Mar 2010 3:58 am
  31. 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 !

  32. Wang on Mon, 29th Mar 2010 4:12 am
  33. 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.

  34. Wang on Mon, 29th Mar 2010 7:12 am
  35. 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.

  36. Andreas on Tue, 27th Apr 2010 6:32 pm
  37. Sandra on Wed, 12th May 2010 5:31 am
  38. Thank you for the nice post. i had the same problem like Wang but now it still works. nice.

  39. Bryan C. on Mon, 24th May 2010 4:42 pm
  40. I fixed the 100 error by removing the “,offline_access” element from the prompt permissions URL and it worked perfectly.

  41. #iranelection on Fri, 11th Jun 2010 12:36 am
  42. Thanks it worked for me

  43. Doug A on Thu, 17th Jun 2010 5:51 pm
  44. 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

  45. Steven Robert on Fri, 18th Jun 2010 12:09 am
  46. Yes Doug, Check your target id , it should be fan pageid

  47. Doug A on Fri, 18th Jun 2010 2:20 pm
  48. 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!

  49. Sam Simpson on Fri, 9th Jul 2010 10:35 pm
  50. 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()

  51. Sam Simpson on Fri, 9th Jul 2010 10:37 pm
  52. 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

  53. Sunil on Thu, 15th Jul 2010 5:07 pm
  54. Jeff on Sat, 24th Jul 2010 10:31 am
  55. 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…

  56. Vrushali on Mon, 1st Nov 2010 9:16 am
  57. 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

  58. Steven Robert on Mon, 1st Nov 2010 12:56 pm
  59. @Vrushali See my other post to post on a fan page. you need to set targetid

  60. Vrushali on Tue, 2nd Nov 2010 12:49 am
  61. 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

  62. dennis on Tue, 16th Nov 2010 9:50 am
  63. 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

  64. baljeet on Sat, 27th Nov 2010 6:25 am
  65. 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”

  66. baljeet on Sat, 27th Nov 2010 7:33 am
  67. 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

  68. Steven Robert on Sat, 27th Nov 2010 8:23 am
  69. Baljeet, You can use the target id to publish on fan page.

  70. baljeet on Sat, 27th Nov 2010 1:06 pm
  71. Thanks Steve !
    Thanks for quick response, Its working now. Have you written any article on how to do similar things on Twitter and LinkedIn ?

  72. Steven Robert on Sat, 27th Nov 2010 11:01 pm
  73. No Baljeet, I will try to prepare that post to for Twitter and LinkedIn

  74. baljeet on Sun, 28th Nov 2010 2:33 am
  75. 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

  76. Alexia Nessel on Sun, 28th Nov 2010 2:59 pm
  77. 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.

  78. baljeet on Mon, 29th Nov 2010 3:26 am
  79. 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

  80. baljeet on Mon, 29th Nov 2010 3:40 am
  81. 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

  82. baljeet on Wed, 1st Dec 2010 1:13 am
  83. 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

  84. jay on Wed, 15th Dec 2010 1:22 pm
  85. 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.

  86. baljeet on Wed, 5th Jan 2011 8:30 am
  87. 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) ?

  88. baljeet on Mon, 24th Jan 2011 12:41 pm
  89. 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 [...]

  90. Hetal on Wed, 29th Jun 2011 6:26 pm
  91. It working awesome.

    Thanks dude, this is what i want to know..

  92. Vishal on Fri, 5th Aug 2011 1:20 pm
  93. 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

  94. jan on Tue, 10th Jan 2012 4:35 pm
  95. 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?

  96. john on Wed, 7th Mar 2012 12:48 pm
  97. 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 ???

  98. Candy on Wed, 9th May 2012 3:17 am
  99. 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

  100. Sotheayuth on Fri, 18th May 2012 4:38 pm
  101. 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

  102. Sotheayuth on Fri, 18th May 2012 9:15 pm
  103. 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

  104. Marios on Wed, 1st Aug 2012 8:33 am
  105. 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!





*
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.
Click to hear an audio file of the anti-spam word

Subscribe without commenting