我试图通过 facebook graph api (graph.facebook.com/me?access_token=token
) 在 node.js 中获取我的 facebook 帐户详细信息,但我无法获取它与:
access_token
= appid
+ '|'
+ appsecret
这是我的代码:
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);
});
});
我得到的错误:
{"error":{"message":"An active access token must be used to query information about the current user.","type":"OAuthException","code":2500}}
最佳答案
编辑:
再次阅读文档后:https://developers.facebook.com/docs/facebook-login/access-tokens .
我知道 facebook 有 4 种类型的 token :
- 用户访问 token
- 应用访问 token = app_id|app_secret
- 页面访问 token
- 客户端 token
App Access Token 用于读取应用设置(不是用户信息)。
而“https://graph.facebook.com/me”是用户信息,所以我们需要使用用户访问 token
使用应用访问 token 的示例:
https://graph.facebook.com/APP_ID/roles?&access_token=APP_ID|APP_SECRET
关于Node.js - 从 facebook graph api 获取我的帐户详细信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20584056/