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

Zeeshan Hassan Memon
  • 8,105
  • 4
  • 43
  • 57
Hakim
  • 3,225
  • 5
  • 37
  • 75

2 Answers2

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

Zeeshan Hassan Memon
  • 8,105
  • 4
  • 43
  • 57
damphat
  • 18,246
  • 8
  • 45
  • 59
  • 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}}` – Hakim Dec 14 '13 at 15:40
  • give me the link to document, and how you you pass params to node? – damphat Dec 14 '13 at 15:45
  • [stackoverflow - trying to get app access token](http://stackoverflow.com/questions/12948809/trying-to-get-app-access-token) – Hakim Dec 14 '13 at 15:47
  • 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 – damphat Dec 14 '13 at 15:54
  • It's the concatenation of the two strings! – Hakim Dec 14 '13 at 15:55
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/43183/discussion-between-h4k1m-and-damphat) – Hakim Dec 14 '13 at 17:12
  • please share code of how to access `user access_token` – Dynamic Remo Jun 30 '17 at 17:02
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

Community
  • 1
  • 1
Hakim
  • 3,225
  • 5
  • 37
  • 75