I am able to get the user's access token and pass it to the post_to_page function. It returns the following error:
Object {message: "(#200) Insufficient permission to post to target on behalf of the viewer", type: "OAuthException", code: 200}
I know the app_id is fine, I set the scope of permissions to be: email,user_likes,publish_actions,publish_stream. Is there a permission I am missing to post on behalf of the viewer?
I feel like I missing one thing.
$('a.post-to-page').click(function(event) {
FB.login(function(response) {
if (response.authResponse) {
console.log('Welcome! Fetching your information.... ');
FB.api('/me', function(response) {
console.log('Good to see you, ' + response.name + '.');
console.log(response);
});
} else {
console.log('User cancelled login or did not fully authorize.');
}
}, {scope: 'email,user_likes,publish_actions,publish_stream'});
FB.getLoginStatus(function(response) {
if (response.status === 'connected') {
console.log(response.authResponse.accessToken);
post_to_page(response.authResponse.accessToken);
}
});
});
function post_to_page(access_token_data)
{
var body = 'Reading JS SDK documentation';
FB.api('/page_id/feed', 'post', { message: body, access_token: access_token_data }, function(response) {
if (!response || response.error) {
console.log(response.error);
} else {
console.log(response.id);
}
});
}