Simple Steps to Publish On FaceBook Fan Page Using PHP

After Done with my previous post 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

define('FB_APIKEY', 'APIKEYxx');
define('FB_SECRET', 'SECRETKEYxxxxxxxxxxxxxxxxxxx');
define('FB_SESSION', 'SESSIONKEYxxxxxxxxxxxxxxxxxxxx');


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 />";


publish on facebook fan wall page using php
That’s it your are now done enjoy!!! publishing on fan’s page wall.

You can see my Fan Page here Where I published using above example.

14 thoughts on “Simple Steps to Publish On FaceBook Fan Page Using PHP”

  1. 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?

  2. 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.

  3. 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)

  4. 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 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,

  5. 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 and very useful discussion is here

    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.

  6. 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.

  7. Hi,
    I am getting ‘user not visible’ error when I run the above script. Can you kindly advise me what could be wrong?


  8. Thanks for that reply Steven. I managed to post to the fan page using your code. But I have 1 problem… The post has my name and profile picture rather than having the ‘page’s’ name and profile picture. I am one of the administrator of this page. Can you kindly let me know how can I post as the page admin and not as self?

  9. this is a great article. I was able to convert this into C#. My app works fine. But, is there a ways you can upload videos into your fan page using facebook api. I can’t find that anywhere. Thanks.

Leave a Reply

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

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