質問

I'm trying to get my facebook account details in node.js via facebook graph api (graph.facebook.com/me?access_token=token), but I can't get it to work with:

access_token = appid + '|' + appsecret

Here is my code:

var https=require('https');

var access_token = process.argv.slice(2)[0] + '|' + process.argv.slice(2)[1];
var options = {
    host: 'graph.facebook.com',
    path: '/me?access_token=' + access_token
};

https.get(options,function(res){
    var data = '';

    res.on('data', function (chunk) {
        data += chunk;
    });

    res.on('end', function() {
        console.log(data);
    });
});

And the error I'm getting:

{"error":{"message":"An active access token must be used to query information about the current user.","type":"OAuthException","code":2500}}

役に立ちましたか?

解決

Edit:

After reading document again: https://developers.facebook.com/docs/facebook-login/access-tokens.

I realize facebook has 4 types of token:

  • User Access Token
  • App Access Token = app_id|app_secret
  • Page Access Token
  • Client Token

App Access Token is used to read the app settings (not the user info).

And "https://graph.facebook.com/me" is for user info so we need to use User Access Token


example of using app access token:

https://graph.facebook.com/APP_ID/roles?&access_token=APP_ID|APP_SECRET

他のヒント

I was missing the &grant_type=client_credentials in the url:
To Get the app Access Token for facebook api.

But the app token isn't the one with which you get information about your user, in this case I need the user access token which I can get from Graph Api Explorer

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