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 为空。
我尝试过的解决方案:
在 Firebase 中打开和关闭选项“避免使用同一电子邮件创建多个帐户”
使用'account.email'或'getEmail()'
困扰我的事情:
- 寻找答案我看到有人提到他们
接受了阅读权限,我没有看到任何弹出窗口要求我做
它。
这是我在 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()
首先,很抱歉,如果已经有 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 为空。
我尝试过的解决方案:
在 Firebase 中打开和关闭选项“避免使用同一电子邮件创建多个帐户”
使用'account.email'或'getEmail()'
困扰我的事情:
- 寻找答案我看到有人提到他们 接受了阅读权限,我没有看到任何弹出窗口要求我做 它。
这是我在 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()