JJJCoder
JJJCoder

Reputation: 16916

Facebook Graph API - (#200) Permissions error on Page Post

I want to post to a Facebook Page feed from JavaScript (as if it were from the page). I log in OK, but when i try to post, it gives the error

"error: Object code: 200 message: "(#200) Permissions error" type: "OAuthException"

In the login, the auth response comes through with the following permissions which i believe are sufficient -

"email,contact_email,manage_pages,publish_pages,publish_actions,public_profile"."

How can i get this working please?

Main Parts (plunk):

function postToMembers(){

    var access_token1 = FB.getAuthResponse()['accessToken'];

    var body = 'Post from code test';
    FB.api('/41622-PAGEID-34/feed', 'post', { message: body, access_token: access_token1 }, function(response) {
      if (!response || response.error) {
        console.log(response); 
      } else {
        alert('Post ID: ' + response.id);
      }
    });

};


function loginAndPost(){
    FB.login(function(response) {
       if (response.authResponse) {
         //Log auth permissions (in the response)
         console.log(response);
         FB.api('/me', function(response) {
          console.log('Successful login for: ' + response.name);
          document.getElementById('status').innerHTML =
            'Thanks for logging in, ' + response.name + '!';
        });

        postToMembers();

       } else {
         console.log('User cancelled login or did not fully authorize.');
       }
     }, {scope: 'publish_actions,publish_pages,manage_pages', return_scopes: true});
};

For info, I have looked at the docs here, here, and here and many StackOverflow posts but can't get it going.

Upvotes: 1

Views: 15912

Answers (1)

andyrandy
andyrandy

Reputation: 73984

There is no permission called "contact_email", there is only "email".

That being said, you need a Page Token to post "as Page". Use /me/accounts to get Page Tokens for your Pages. The permission error most likely means that you don´t have the appropriate permissions to post to the Page with your Access Token. Make sure it is a Page you manage, and make sure the Access Token includes the publish_pages permission. You can debug your Access token in the Debugger: https://developers.facebook.com/tools/debug/

Also, make sure you are trying with an App Admin. Without review, those additional permissions only work for Users with a role in the App. See information about Login Review in the docs: https://developers.facebook.com/docs/facebook-login/review

Upvotes: 2

Related Questions