简体   繁体   English

PassportJS获取Facebook用户位置

[英]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.

相关问题 如何在PassportJS中获取Facebook用户图像? - How get the facebook user image in PassportJS? passportjs +facebook + 当前用户 - passportjs +facebook + current User PassportJs。 如何在没有重定向用户的情况下获得facebook重定向uri后调用passport.authenticate(&#39;facebook&#39;) - PassportJs. How can I get facebook redirect uri without redirecting user after call passport.authenticate('facebook') Passportjs返回的Facebook ID与Facebook用户ID不匹配 - facebook id return by passportjs doesn't match with facebook user id 使用PassportJS在Facebook登录后将用户重定向到原始URL - Redirect the user to origin URL after Facebook login using PassportJS PassportJS - 如何在用户单击某个按钮时获取用户信息? - PassportJS - How to get user information when user clicks a certain button? SailsJS和PassportJS Facebook身份验证 - SailsJS and PassportJS Facebook auth 当我在passportJS中反序列化用户时,用户没有通过 - When i deserializeUser in passportJS the user does not get passed 使用Passportjs从Angularjs(http get / resource)进行用户身份验证 - user authentication from Angularjs ( http get / resource ) using Passportjs PassportJS:如何在我的视图中获取 req.user - PassportJS: How to get req.user in my views
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM