无法在Firebase中使用Google身份验证获取电子邮件 [英] Not getting the email using Google Authentication in Firebase
问题描述
我正在使用Firebase提供的代码进行Google身份验证,以某种方式,身份验证成功,但是电子邮件未正确导入到Firebase.
I am using the code provided by Firebase for Google Authentication and somehow, the authentication was successful but the email was not correctly imported to Firebase.
https://firebase.google.com/docs/auth/ios/谷歌登录
如下面的屏幕截图所示,电子邮件为空白.当我看着调试器时,它显示为nil.
我单击了允许在身份验证期间查看电子邮件",但我认为仍有一些设置未正确完成.有人可以帮我看看吗?我有兴趣使用电子邮件为每个用户创建用户名.
As you can see in the screenshot below, the email is blank. When I looked at the debugger, it is showing nil.
I clicked allow viewing email during authentication but I think there are still some settings that was not done correctly. Could someone help me to take a look? I am interested to use the email to create the username for each user.
func signIn(signIn: GIDSignIn!, didSignInForUser user: GIDGoogleUser!, withError error: NSError!) {
if let error = error {
print(error.localizedDescription)
return
}
let authentication = user.authentication
let credential = FIRGoogleAuthProvider.credentialWithIDToken(authentication.idToken,
accessToken: authentication.accessToken)
FIRAuth.auth()?.signInWithCredential(credential) { (user, error) in
if error != nil {
print(error?.localizedDescription)
return
}
print("User logged in with Google...")
self.performSegueWithIdentifier("ToHome", sender: nil)
}
}
推荐答案
该电子邮件未在Firebase控制台上显示,因为您允许用户使用同一封电子邮件创建多个帐户.如果您导航到 Auth->登录方式,您可以将选项设置为避免使用同一封电子邮件创建多个帐户.完成此操作后,创建用户时电子邮件将开始显示.
The email is not showing on firebase console because you are allowing users to create multiple accounts with the same email. If you navigate to Auth -> Sign-in method you can set the option to Avoid creating multiple accounts with the same e-mail. After doing so the emails will start to appear when creating the user.
在此处不确定,但是如果您仍要创建多个帐户并将用户电子邮件放在应用程序端,我想您在创建用户时需要将电子邮件存储在firebase数据库上.
Not sure here but, if you still want to create multiple accounts and have the user email on the application side I guess that you will need to store the email on firebase database when creating the user.
这篇关于无法在Firebase中使用Google身份验证获取电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!