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.

October 4th, 2009 05:18
[...] Meeting of Minds » Blog Archive » How to Post to the Facebook Fan … [...]
October 5th, 2009 10:15
Hey there.. I did pretty much exactly what you did, and I’m still unable to publish on behalf of the page.
When I set the target id to the page id, it publishes on behalf of the administrator. When I set the page id as the “uid”, it generates an “incorrect signature” error. Do you know what I’m doing wrong?
October 5th, 2009 21:30
Arjun,
Try setting the target_id to null and the uid field to the page id.
-Senthil
October 14th, 2009 01:08
Does this code work for anybody? I have prompted the permissions and in the api I tried setting the target_id to the page_id and the uid to the page_id and it still users the User as the Sender and not the Page itself.
I even tried the target_id as null and setting the uid to the Page_ID and still passes through as the user and not the Page itself.
Any suggestions?
October 29th, 2009 21:30
This works for most of us. Are you sure you are the page admin ? Can you post the exact call you are making?
October 31st, 2009 19:14
I am having the exact same problem… here’s my code
I want to post to the page on behalf of the page!
If I use actor_id or uid it simply uses it in the form, but no where else…
function callPublish(msg, attachment, action_link, target_id,uid )
{
FB.ensureInit(function ()
{
var attachment = {’media’:[{'type':'image','src':'http://bit.ly/AJTnf','href':'http://bit.ly/hifZk'}]};
var target_id = ‘91713273438′;
var action_link = [{'text':'FBSharer','href':'http://www.coactlab.com/fbsharer/'}]
var uid = ‘91713273438′;
FB.Connect.streamPublish(”, attachment,action_link,target_id,uid);
});
}
October 31st, 2009 20:44
Rob Edwards,
Are you seeing any error messages? Can you post your error message?
One more thing you can try –
If you are logged in as the admin of the page, try setting the target_id to null and the uid to the page id.
November 2nd, 2009 16:43
I don’t get any errors, it just won’t post as the page. I’ve already obtained permissions from the user to post on the page that they are an admin of, but no luck with your suggestion. Thanks though!
Rob
November 3rd, 2009 06:08
Hi Senthil,
I have the permission set for my app to publish to my page.
Following is the code I’m trying :
function publish2FB()
{
var message = ‘This is the status update’;
var attachment = {’name’:'title text’,'href’:'http://mysite.com’,'href’:'http://mysite.com’, ‘caption’:'Source:fb.myTestApp’,'description’:'tempor. Proin vitae lectus ut massa sagittis congue. Phasellus feugiat vehicula ultricies. Integer neque ante, ullamcorper at aliquet eu, ultricies quis metus. Nullam placerat congue enim, quis cursus dui pellentesque vel.’,'media’: [{'type': 'video', 'video_src': 'http://www.youtube.com/watch?v=7nfsiDFOYL0', 'preview_img':'http://i4.ytimg.com/vi/7nfsiDFOYL0/default.jpg', 'video_link': 'http://www.thestranger.co.nr','video_title': 'Smack That'}]};
FB.Connect.streamPublish(message, attachment, null,”,null,null,true,’page_id’);
}
FB.init(”API_key”, “xd_receiver.htm”);
Now,can you please tell me :
1. If I’ll be able to post from my external website to my page without prompting the feed dialog.
2. If I can post on the Page feed even when I am actually not logged in.
3. I can log in and can publish on behalf of my page but with the prompt dialog.
Please tell me what is actually I am missing