无法在node.js中获得location
hometown
和birthday
用户(使用access_token),但它适用于浏览器和Graph API Explorer
编辑:我正在使用Passport跟随access_token
获取scopes
:
app.get('/auth/facebook', passport.authenticate('facebook', { scope : ["email", "user_location", "user_hometown", "user_birthday"] }));
profileFields: ['id', 'emails', 'name', 'birthday', 'gender', 'location', 'hometown', 'locale', 'age_range']
浏览器网址:
https://graph.facebook.com/v2.5/me?fields=id,name,location,age_range,email,birthday,hometown,gender&access_token=Access_Token_Here
响应:
{
"id": "7766..........",
"name": "John Doe",
"location": {
"id": "11..........",
"name": "Berlin, Germany"
},
"age_range": {
"min": 21
},
"email": "john@doe.com",
"birthday": "09/09/1999",
"hometown": {
"id": "10...............",
"name": "Green Town"
},
"gender": "any"
}
Node.js尝试1:
var graph = require("fbgraph");
graph.setAccessToken("token_here");
graph.get("me?fields=gender,name,age_range,email,picture,birthday,about,bio,hometown", function(err, res) {
if(err)
console.log("err ", err);
else
console.log("res ",res); // data here
});
Node.js尝试2:
var request = require('request');
request("https://graph.facebook.com/v2.5/me?fields=id,name,location,age_range,email,birthday,hometown,gender&access_token=" + token,function(err, resp, body){
if(!err && resp.statusCode == 200){
console.log(body);
}
});
Node.js对两次尝试的响应:
{
"id": "7766..........",
"name": "John Doe",
"age_range": {
"min": 21
},
"email": "john@doe.com",
"gender": "any"
}
//location, hometown, birthday are not coming here