Google 中的 GetEmail() Null 使用 Kotlin 使用 Firebase 登录

GetEmail() Null in Google Login with Firebase using Kotlin

首先,很抱歉,如果已经有 post 解决了我的问题,但我找到的没有解决问题。

我正在使用电子邮件创建一个登录名并通过(工作正常)加上使用 google 的登录名,登录名有效但无论是在 Firebase 控制台还是在带有 'account.email' 的代码中我都看不到电子邮件。

Firebase Console

binding.btGoogle.setOnClickListener() {
            val googleConfig: GoogleSignInOptions =
                GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
                    .requestIdToken(getString(R.string.default_web_client_id)).build()
            val googleClient: GoogleSignInClient = GoogleSignIn.getClient(this, googleConfig)
            googleClient.signOut()
            startActivityForResult(googleClient.signInIntent, GOOGLE_SIGN_IN)
        }
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)

        if (requestCode == GOOGLE_SIGN_IN) {
            val task: Task<GoogleSignInAccount> = GoogleSignIn.getSignedInAccountFromIntent(data)
            try {
                val account: GoogleSignInAccount? = task.getResult(ApiException::class.java)
//here 'account.email' is already null
                if (account != null) {
                    val credential: AuthCredential = GoogleAuthProvider.getCredential(
                        account.idToken,
                        null
                    )

                    FirebaseAuth.getInstance().signInWithCredential(credential).addOnCompleteListener() {
                            if (it.isSuccessful) {
                                showHome(account.email ?: "", ProviderType.GOOGLE)
                            } else {
                                showAlert()
                            }
                        }
                }
            } catch (e: ApiException) {
                showAlert()
            }
        }
    }

正在调试,我可以看到其他属性,例如 displayName、givenName、idToken...但是 email 为空。

我尝试过的解决方案:

困扰我的事情:

这是我在 Whosebug 中的第一个问题,而且我的英语不是最好的...如果我做错了什么,抱歉,提前谢谢你。

天哪,我真是太蠢了,漏了一个字:)

我有这个:

val googleConfig: GoogleSignInOptions =
                GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
        .requestIdToken(getString(R.string.default_web_client_id))
        .build()

我需要这个:

val googleConfig: GoogleSignInOptions =
                GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
        .requestIdToken(getString(R.string.default_web_client_id))
        .requestEmail()
        .build()