Simple Steps to Publish On FaceBook Fan Page Using PHP
After Done with my previous post http://blog.theunical.com/facebook-integration/5-steps-to-publish-on-a-facebook-wall-using-php/ that only publish’s on a Facebook wall.
So now we will see how to publish on a facebook Fan’s page.
First we need to follow the 5 steps that I described in my previous post Next just create a Fan Page in Facebook.
Then get the page ID that you can get by the Page URL.
Then replace the APIKey, Secret Key and Session Key with your keys.
Then replace $target_id with your page id. That is Fan’s Page id.
Here is the code in PHP to publish on a Facebook FAN Page
<?php
define('FB_APIKEY', 'APIKEYxx');
define('FB_SECRET', 'SECRETKEYxxxxxxxxxxxxxxxxxxx');
define('FB_SESSION', 'SESSIONKEYxxxxxxxxxxxxxxxxxxxx');
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';
$target_id ="273641842409";
if( $facebook->api_client->stream_publish($message, $attachment,$action_links, $target_id))
echo "Added on FB Wall on Fan Page";
} catch(Exception $e) {
echo $e . "<br />";
}
?>
That’s it your are now done enjoy!!! publishing on fan’s page wall.
You can see my Fan Page here http://www.facebook.com/pages/Fan-Page/273641842409?v=wall Where I published using above example.
Similar Posts
- » Xbox 360's <b>Facebook</b> and Twitter Look Good, Shame About Last.fm <b>...</b>
- » Photo album and contact app like on the HTC (<b>Facebook integration</b> <b>...</b>
- » SELECT INTO or <b>CREATE TABLE</b> Free source code and <b>...</b>
- » Is Microsoft Bringing XBOX Live to Windows Mobile?
- » Post video on facebook wall using PHP
Comments
7 Comments on Simple Steps to Publish On FaceBook Fan Page Using PHP
-
Frank on
Wed, 17th Feb 2010 8:07 pm
-
Steven Robert on
Wed, 17th Feb 2010 9:23 pm
-
Ondra on
Thu, 18th Feb 2010 6:17 am
-
Frank on
Thu, 18th Feb 2010 11:36 am
-
Sven on
Thu, 18th Feb 2010 1:00 pm
-
Ondra on
Fri, 19th Feb 2010 12:05 am
-
Steven Robert on
Mon, 1st Mar 2010 2:22 am
thanks for this great post, it did help me a lot!
this is just what i want to do, but instead of having it posted from my account, i would like the fan page post as itself, so instead of “Tut TheUnical From My App: publish steven on facebook Fan Page” it would say “Fan Page From My App: publish steven on facebook Fan Page”
is this possible too?
thanks!
Hi Frank,
Do you want to publish only on fanpage? and not on your wall?
Hello,
I would like to do the same as Frank wanted. To post to fan page as fan page that it says: “Fan Page From My App: publish steven on facebook Fan Page” and not “Ondra My App: publish steven on facebook Fan Page”
I do not want to post to my wall. Just to fan page.
Please do you know the way how to achieve this?
Thank you.
yes, exactly, my scenario is to post only on the fanpage (i want the posting to happen automatically when certain events occur on my server)
Hello,
thanks for the great informations. I think i have the same problem as Frank. I search for a way to publish on my fanpage not as a fan but as the admin of the fanpage. The Website links to the related facebook fan page with two test entries. Second entry was done using your script (from Sven M…. as a fan) and third was done over the website (from beatillz.de as the admin). Is it possible to publish on the fanpage with the script looking like the third entry ? I hope you can understand what my problem is. Thanks in advance!
Best regards,
Sven
I have finally figured it out. The problem was that you (as fan page’s admin) have to give facebook application extended permission to publish to pages’s wall. The only way how to do it is described here http://thinkdiff.net/facebook/update-facebook-page-status-automatically/ and very useful discussion is here http://forum.developers.facebook.com/viewtopic.php?pid=170278
Than you can call $facebook->api_client->stream_publish($message, $attachment,$action_links, $target_id) and it posts to the wall as fan page not as the user.
Hi Sven,Ondra and Frank,
You are referring that you see the posts that are done on your Fan page, on your own profile stream. This is done by Facebook , in the same way that you see the actions of your friends or any other pages that you are Fan of on a wall.
Solution: In that case you cannot do anything, nor is this a misconfiguration and more a Facebook feature that causes the duplicating of wall.
Tell me what you're thinking...
and oh, if you want a pic to show with your comment, go get a gravatar!






