Hey folks, I’m having a tricky issue with my Android application where I’m using Credential Manager for Google sign-ins. It normally returns the correct email address when I use credential.getId(), but with one of my test Gmail accounts, it returns a long number instead.
Here’s an adapted sample of my implementation:
fun performGoogleSignIn(activity: Activity) {
val signInConfig = GoogleSignInOption.Builder()
.setServerClientId(NEW_SERVER_ID)
.build()
val credentialRequest = CredentialRequest.Builder()
.addSignInOption(signInConfig)
.build()
CredentialManager.getInstance(activity).getCredential(credentialRequest) { response ->
val currentCredential = response.credential
println("User Identifier: ${currentCredential.id}")
}
}
While most accounts correctly display the email, one account shows a numeric ID instead. I’m on Credential Manager version 1.5.0-beta01. Any suggestions or insights on this behavior? Thanks!
I’ve encountered this issue in my projects as well. It’s related to how Google handles account identifiers for certain legacy accounts. To resolve this, you should modify your GoogleSignInOptions to explicitly request the email scope. Here’s how you can adjust your code:
val signInConfig = GoogleSignInOption.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestEmail()
.setServerClientId(NEW_SERVER_ID)
.build()
By adding .requestEmail(), you ensure that the email is always returned, regardless of the account type. If you still face issues, consider using the Google People API as a fallback to fetch the user’s email address. This approach has worked consistently in my experience with various Google account types.
hey john, i ran into this too. it’s cuz some older google accounts use numeric ids instead of emails. to get the email, try using GoogleSignInAccount.getEmail() after signin. if that don’t work, u might need to request the email scope explicitly in ur GoogleSignInOptions. hope this helps!
I’ve encountered this behavior with some Google accounts in my projects. The issue arises because certain legacy accounts return a numeric identifier instead of the email address. In my experience, combining Credential Manager with the Google Sign-In API is a reliable workaround. After obtaining the credential, I use GoogleSignIn.getSignedInAccountFromIntent() to retrieve the full account details, which always includes the email. Make sure that you have integrated all necessary dependencies for the Google Sign-In API in your build. This approach has been successful across various account types.