How to Post to a Facebook Fan Page on Behalf of the Page.

Quick Summary

Use the Facebook.showPermissionDialog FBJS api call to authorize the Page for which you are an admin. Set the enableProfileSelector to true and include the page id in the profileSelectorIds. Once  the app user has authorized and given the extended permissions, You can use the Stream.publish api call with the page id as the target id and publish on behalf of the page.

The Details – Posting to the Facebook Fan Page on behalf of the page.

Facebook allows you to create pages aka fan pages for your website, business, product, or almost just about anything. Page admins can customize their pages by adding facebook applications from the app directory to their pages. Using Facebook applications for fan pages allows you to integrate into the social connections of your fans better.

Applications with extended permissions can publish to a user’s wall, news feed stream or profile. In addition, applications can now publish to a Page wall.

Publishing to a Page as a user is fairly simple with Stream.publish facebook api, the Facebook developer api covers this well. You can prompt the user for  ‘publish_stream’ extended permissions using the  fb:prompt-permission FBML tag, preferably during an initial set up workflow.

Once the user has authorized your app and given the extended permission, You just have to set the target id to the page id in your Stream.publish api call.  See the sample php api call below,

$facebook->api_client->stream_publish($message, $attachment,$action_links, $target_id);

Publishing on behalf of  a page is trickier.  Page admins have to authorize the app to publish on behalf of a page. You can do this by using

the Facebook.showPermissionDialog FBJS api call.

Facebook.showPermissionDialog('publish_stream, read_stream', ondone, showProfileSelector, [1234,2345]);

Just replace the profileSelectorIds ( [1234, 2345]) and include the page id in the FBJS call above. This should bring up a permission dialog and show

a “profile  selector” including the page for which you are an admin.

You should now be able to use the Stream.publish api call with the page id as the target id and publish on behalf of the page.

Leave a Reply