[英]Get email with Facebook Firebase Simple Login
我正在使用Facebook与Firebase简单登录。 我试图通过我的FirebaseSimpleLogin实例中的user.displayName
成功获取该人的真实姓名。 当我尝试使用user.email
收到他们的电子邮件时,它会返回undefined
。 我在Google+上做了同样的事情,它运行得很好,没有返回任何未定义的内容。 这是我的代码:
var chatRef = new Firebase('https://******.firebaseio.com');
//No, i didn't actually put this firebase name in my code =P
var auth = new FirebaseSimpleLogin(chatRef, function(error, user) {
if (error) {
// an error occurred while attempting login
console.log(error);
alert('An error occurred while trying to log you in.' + error);
} else if (user) {
// user authenticated with Firebase
console.log('Name: ' + user.displayName + ', email: ' + user.email);
//With google, 'Name: John Doe, email: johndoe@example.com' is returned
//With facebook, 'Name: John Doe, email: undefined' is returned
} else {
// user is logged out
}
});
function google() {
auth.login('google', {
rememberMe: true
});
}
function facebook() {
auth.login('facebook', {
rememberMe: true,
scope: 'email'
});
}
所以,我的问题是,如何通过Facebook Firebase简单登录获取用户的电子邮件地址? 先谢谢大家。
在开始之前,查看用户对象上已存在的属性的最佳方法是将控制台日志添加到现有的身份验证检查中。
使用:
else if (user){
console.log(user);
}
您将知道当前设置的用户对象上存在哪些属性。 可能需要其他许可 - 见下文。
根据facebook dev docs ,权限是与登录请求或API调用一起传递的字符串。 以下是两个权限示例:
例如,如果您将登录按钮添加到Web应用程序并通过scope参数询问电子邮件和user_likes,则首次登录时系统会提示此对话框:
并且每个firebase文档
以下是会话将存储30天的示例(由于“记住我”设置),我们还要求对电子邮件和user_likes进行一些扩展权限:
auth.login('facebook', {
rememberMe: true,
scope: 'email,user_likes'
});
因此,除非您在auth.login参数中添加了其他权限,否则您将无法访问用户的主电子邮件地址。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.