无法在Firebase中使用Google身份验证获取电子邮件

Dar*_*ong 7 google-authentication ios firebase swift firebase-authentication

我正在使用Firebase提供的代码进行Google身份验证,并且以某种方式,身份验证成功,但是电子邮件未正确导入到Firebase。

https://firebase.google.com/docs/auth/ios/google-signin

如您在以下屏幕截图中所见,该电子邮件为空白。当我看着调试器时,它显示为nil。
我单击了“允许在身份验证期间查看电子邮件”,但是我认为仍有一些设置未正确完成。有人可以帮我看看吗?我有兴趣使用电子邮件为每个用户创建用户名。

在此处输入图片说明

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)
    }
}
Run Code Online (Sandbox Code Playgroud)

ado*_*srs 7

该电子邮件未显示在Firebase控制台上,因为您允许用户使用同一封电子邮件创建多个帐户。如果导航到“身份验证”->“登录方法”,则可以将选项设置为“ 避免使用同一电子邮件创建多个帐户”。此后,创建用户时,电子邮件将开始出现。

在此处输入代码

在这里不确定,但是,如果您仍然想创建多个帐户并将用户电子邮件放在应用程序端,我想您在创建用户时需要将电子邮件存储在firebase数据库上。

  • @framled ...对于响应来说已经晚了3年..;-)..但我遇到了同样的问题,要获取电子邮件作为firebase中的标识符,你可以这样做 `this.googleProvider = new app.auth .GoogleAuthProvider(); this.googleProvider.addScope("email");` ... addScope 方法对我有用 (3认同)