Okay what I want is to post to the Facebook Page as an Page(This is developing mode application only viewable to ne). I have done with Facebook login.
So basically I ask for 2 permissions
and they are
- Manage Pages
- Publish Pages
I can post to the page using the Facebook graph explorer tool
but can't via my Javascript
code.
Here is the code that I write using JS. This code is written inside a function.
FB.api('me/accounts', function(response){
token = response.data[0].access_token;
post_with_token(token);
});
function post_with_token(token){
var message = $('#post_body').html();
var page_id = 'page_id';
FB.api('page_id/feed', 'post',
{ message : message,
access_token : token},
function (response){
console.log(response);
});
The error object in the console says this
message: "(#200) The user hasn't authorized the application to perform this action"
Both the apps My and Graph explorer have the same permissions granted.Is any new permission to be asked. I am unable to figure out what exactly the problem is.Correct me if I am wrong anywhere.
I got the answer that I posted below but didn't got why I need additional permission.?
publish_pages
has only been introduced with Graph API version 2.3.Before that,
publish_actions
was used to allow posts on pages by the page as well – now with v2.3, they have made that into two separate permissions.publish_actions
is for everything you publish as/in the name of a user, andpublish_pages
is for publishing as a page.Graph API Explorer has API version 2.3 selected by default – that is why your call was successful there. Most likely, with your own API call from your JS code, you did not use v2.3, but specified a lower API version when initializing the JS SDK.
So just specify
version: 'v2.3'
in yourFB.init
parameters (see Basic Setup section in JS SDK docs), and it should work fine withpublish_pages
.