Is it possible to post to pages that you are an admin for using the Facebook Javascript SDK?
I am able to write on my own wall but not on the wall of pages I am an admin for. I am using the code below (Javascript SDK):
FB.ui(
{
method: 'stream.publish',
message: 'getting educated about Facebook Connect',
attachment: {
name: 'Connect',
caption: 'The Facebook Connect JavaScript SDK',
description: (
'A small JavaScript library that allows you to harness ' +
开发者_运维问答 'the power of Facebook, bringing the user\'s identity, ' +
'social graph and distribution power to your site.'
),
href: 'http://github.com/facebook/connect-js'
},
action_links: [
{ text: 'Code', href: 'http://github.com/facebook/connect-js' }
],
user_message_prompt: 'Share your thoughts about Connect',
target_id: '170500829645508',
uid: '100001920038281'
},
function(response) {
if (response && response.post_id) {
alert('Post was published.');
} else {
alert('Post was not published.');
}
}
);
}
Where target ID is the page I admin and uid is my account user id. When I run this code I keep getting the error message:
An invalid target was specified: 170500829645508. The target must be a page, event, or user that the actor can post on the wall of.
Am I doing something wrong here?
You need the manage_pages extended permission to do this. Once the permission is granted you can query graph.facebook.com/me/accounts to retrieve an API token that can post to a page's wall. Check out Facebook's extended permissions here: http://developers.facebook.com/docs/authentication/permissions.
I ended up using this method which works for posting to a page that I admin. Haven't figured out how to include attachments this way though...
var wallPost = {
access_token: ".........................",
message: 'Here is some more stuff'
};
FB.api('/me/feed', 'post', wallPost, function(response) {
if (!response || response.error) {
alert('Error occurred:' + response.error.message);
} else {
alert('Success!');
}
});
精彩评论