我创建了一个允许用户使用Facebook登录的Meteor应用。为此,我使用accounts-ui和accounts-facebook软件包。这很好用。
如何在用户登录后检索用户的电子邮件地址?我了解这需要特殊许可,因此我在Facebook开发者网站的应用设置中添加了email
作为“用户和朋友的权限”。在Meteor文档之后,我还设置了Account.ui.config
,如下所示:
Accounts.ui.config({
requestPermissions: {
facebook: ['email'],
},
passwordSignupFields: 'USERNAME_AND_EMAIL'
});
正如预期的那样,当我的应用程序的用户使用Facebook登录时,它会正确地要求他们共享他们的电子邮件地址。但是我该如何检索呢?用户文档只包含_id
和profile.name
。
答案 0 :(得分:9)
Facebook用户的电子邮件地址存储在[userDocument].services.facebook.email
中,该地址未发布到客户端,但可以使用Meteor.methods
和{{1从服务器或客户端访问}}
答案 1 :(得分:0)
这会将Facebook个人资料信息添加到客户端用户对象。
Accounts.onCreateUser (options, user) ->
if options.profile
user.profile = options.profile
# get profile data from Facebook
result = Meteor.http.get "https://graph.facebook.com/me", {
params: access_token: user.services.facebook.accessToken}
if !result.error && result.data
#if successfully obtained facebook profile, save it off
#the user can access the profile object on the client
user.profile.facebook = result.data;
return user
在服务器端可以访问facebook.accesstoken ...所以用它来获取完整的FB信息并将其保存到客户端用户对象..
立即在控制台中ping Meteor.user()以获取FB信息。
不要认为这是在客户端上提供FB信息方面的最佳做法..