Get user access token facebook access token in node

2.8k Views Asked by At

I'm trying to make a call to the Facebook Graph API, I'm using node & express for this, it's my first time using them, when I make a call to the API I get the error below, how can I get the access token or set it so the call goes through ?

 message: 'Invalid OAuth access token.',
 type: 'OAuthException',
 code: 190,
 fbtrace_id: 'hgjhguoiu' }

// This is the call to API I'm making :

FB.api('4', function (res) {
 if(!res || res.error) {
   console.log(!res ? 'error occurred' : res.error);
   return;
 }
   console.log(res.id);
   console.log(res.name);
});

// This is the authentication call:

app.get('/auth/facebook/callback',
 passport.authenticate('facebook', {
   successRedirect : '/',
   failureRedirect: '/login'
 }));

Thanks

1

There are 1 best solutions below

0
On

I know this is 12 months old, but anyways:

I am using 'fb' (https://www.npmjs.com/package/fb) for node and I had the same errors as described.

To authenticate your request you just have to write FB.setAccessToken(<your_token>);

You need a different token for different purposes. You can read about them here: https://developers.facebook.com/docs/facebook-login/access-tokens/?locale=de_DE

Hope it helps anyone.