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:

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

56 thoughts on “Publish on Facebook Fan Page as fan user Using PHP”

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

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

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

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

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

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

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