Can't Post to Facebook Page using JS

1k views Asked by At

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

  1. Manage Pages
  2. 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.?

3

There are 3 answers

1
CBroe On BEST ANSWER

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, and publish_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 your FB.init parameters (see Basic Setup section in JS SDK docs), and it should work fine with publish_pages.

0
AudioBubble On

The error implies exactly what it says. They've designer their API so it's not going to let you post without proper authorization first.

Facebook provides a guide on how to give proper authorization to your registered app

0
Suraj Palwe On

Okay I solved the problem . I have to ask for publish_actions permission also. So I asked through the Login Dialog and used the same code as above to post to the page!