質問

I want to post into the a Facebook page where the user is admin. Here is the code I have

FB.init({appId: "***********", status: true, cookie: true, frictionlessRequests: true});

var page = null;

function postToPage(page, msg){
  FB.api('/'+page.id+'/feed', 'post', { message: msg, access_token: page.access_token },
     function(res) { console.log(res) }
  )
}



FB.login(function(response) {
  if (response.authResponse) {
    // user is logged in and granted some permissions.
    FB.api('/me/accounts', function(response) { 
        console.log(response); 
        page = response.data[0]; 
        postToPage(page, 'hello fb-page world');
    })
   } else {
        // User cancelled login or did not fully authorize.
   }
}, {scope:'read_stream,publish_stream,offline_access, manage_pages,status_update'});

It does not work and when I look at the console, I have the error:

(#200) The user hasn't authorized the application to perform this action  

Am I missing an authorization in the scope?

役に立ちましたか?

解決 2

Even though the user granted your application access to their public profile, this doesn't mean that all the required permissions were granted.

See https://developers.facebook.com/docs/reference/javascript/FB.login/v2.0#permissions for how you can verify which permissions has been granted.

他のヒント

Try this out

<body>
<div id='fb-root'></div>
<script src='http://connect.facebook.net/en_US/all.js'></script>
<p>
    <a href="javascript:;" onclick='postToFeed(); return false;'>Post to Group</a>
</p>
<p id='msg'></p>

<script> 
  FB.init({appId: "Yourappid", status: true, cookie: true});

  function postToFeed() {

    // calling the API ...
      FB.api('/Pageid/feed', 'post', 
              { 
                  message     : "It's awesome ...",
                  link        : 'Link',
                  picture     : 'Imageurl',
                  name        : 'Featured of the Day',
                  to: 'Pageid',
                  from: 'Pageid',
                  description : 'Your description'
          }, 
          function(response) {

              if (!response || response.error) {
                  alert(JSON.stringify(response.error));
              } else {
                  alert('Post ID: ' + response.id);
              }
          });
  }

</script>
</body>

Another Way Main challenge is getting permanent access token that will let us act on behalf of a page admin, the rest is very similar to making a regular wall post. Getting access token would require asking one of page admins for manage_pages extra permissions and then retrieving their "accounts" information that would contain access_token fields for every page where they have admin permissions.

FB.login(function() {
    FB.api('/me/accounts', 'get', {}, function(response) {
        console.log(response);
    });
}, {perms:'publish_stream,offline_access,manage_pages'});

Pass just retrieved access token among other wall post parameters

//API init code is omitted
var wallPost = {
    access_token: "<ACCESS_TOKEN>",
    message: 'Hello, World!'
};

FB.api('/me/feed', 'post', wallPost, function(response) {
    if (!response || response.error) {
        alert('Error occurred');
    } else {
        alert('Success!');
    }
});

Key is to get right access token. you can try firebug in browser and test your access token which you get here https://developers.facebook.com/tools/debug/

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top