4

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}}

2 Answers 2

5

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

Sign up to request clarification or add additional context in comments.

7 Comments

I know the | operator in js but is this token permanent if used like this? it's not working, anyway giving me this error: {"error":{"message":"Invalid OAuth access token.","type":"OAuthException","code":190}}
give me the link to document, and how you you pass params to node?
The document says: "graph.facebook.com/endpoint?key=value&access_token=app_id|app_secret", they tell us provide 1 of the two params, not both
It's the concatenation of the two strings!
|
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.