[英]PassportJS to get Facebook User Location
I've attempted to set my strategy to get a user's home in two ways, and neither of which work. 我试图设定我的策略以两种方式获得用户的家,而且两者都不起作用。 Does anyone have code for PassportJS to get a user's address (just city and state)?
有没有人有PassportJS代码来获取用户的地址(只是城市和州)?
Strategy attempting both "location" and "address": 尝试“位置”和“地址”的策略:
profileFields: ['id', 'name','picture.type(large)', 'emails', 'displayName', 'location', 'address', 'about', 'gender'],
Attempting to get using address as seen here portablecontacts.net : 试图得到尽可能在这里看到使用地址portablecontacts.net :
user.facebook.location = profile.address.locality + ', ' profile.address.region;
Edit: Simpler answer 编辑:更简单的答案
Those location fields not yet mapped in the code from their Portable Contacts schema to Facebook's own schema. 那些位置字段尚未在代码中从其可移植联系人架构映射到Facebook自己的架构。 You can see that map here (and the absence of those two fields).
你可以在这里看到这个地图(并且没有这两个字段)。
Instead, simply use the Facebook schema directly. 相反,只需直接使用Facebook架构。 So the profileFields array should include the
location
field, then when you call authenticate, you need to request that field from Facebook: 因此,profileFields数组应包含
location
字段,然后当您调用authenticate时,您需要从Facebook请求该字段:
passport.authenticate('facebook', { scope: ['email', 'public_profile', 'user_location'] }));
Note that in the scope array, it is referred to as user_location
but in the profileFields array it is just location
请注意,在作用域数组中,它被称为
user_location
但在profileFields数组中,它只是location
在范围内使用它时无效,在声明策略中使用passport.use(new fbStrategy({ clientID: fbClientId, clientSecret: fbClientSecret, callbackURL: fbCallback, profileFields: [ 'location', // <- HERE 'email', 'first_name','last_name', 'picture.type(large)', 'link' ] }, function(accessToken, refreshToken, profile, cb) { .... }) )
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.