简体   繁体   English

在节点中获取用户访问令牌facebook访问令牌

[英]Get user access token facebook access token in node

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 ? 我正在尝试调用Facebook Graph API,为此我正在使用node&express,这是我第一次使用它们,当我调用API时,出现以下错误,如何获取访问令牌还是对其进行设置,以便电话能够通过?

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

// This is the call to API I'm making : //这是我正在调用的API:

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

I know this is 12 months old, but anyways: 我知道这已经12个月了,但是无论如何:

I am using 'fb' ( https://www.npmjs.com/package/fb ) for node and I had the same errors as described. 我正在对节点使用'fb'( https://www.npmjs.com/package/fb ),并且遇到与上述相同的错误。

To authenticate your request you just have to write FB.setAccessToken(<your_token>); 要验证您的请求,只需编写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 您可以在这里阅读有关它们的信息: https : //developers.facebook.com/docs/facebook-login/access-tokens/?locale=de_DE

Hope it helps anyone. 希望它能帮助任何人。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM