I’m working on an Android app and need help with Google Sign-In and Google Drive API authorization. I’ve set up CredentialManager for sign-in, but I’m stuck on the next steps.
Here’s what I’ve done so far:
fun startGoogleSignIn() {
val credManager = CredentialManager.create(context)
val googleIdOption = GetGoogleIdOption.Builder()
.setServerClientId(CLIENT_ID)
.build()
val request = GetCredentialRequest.Builder()
.addCredentialOption(googleIdOption)
.build()
credManager.getCredentialAsync(
request,
CancellationSignal(),
executor,
object : CredentialManagerCallback<GetCredentialResponse, GetCredentialException> {
override fun onResult(result: GetCredentialResponse) {
processSignInResult(result)
}
override fun onError(e: GetCredentialException) {
Log.e(TAG, "Sign-in error: ${e.message}")
}
}
)
}
I’m unsure how to proceed with the Google ID token I receive. The docs mention server-side validation, but I don’t know how to implement that.
Also, I’m having trouble authorizing the Google Drive API. When I try to use Google Identity Services for this, I get a null pointer exception:
fun authorizeDriveApi() {
val scopes = listOf(Scope(DriveScopes.DRIVE_READONLY))
val authRequest = AuthorizationRequest.Builder()
.setRequestedScopes(scopes)
.build()
Identity.getAuthorizationClient(context)
.authorize(authRequest)
.addOnSuccessListener { result ->
// Handle result
}
.addOnFailureListener { e ->
Log.e(TAG, "Drive API auth failed", e)
}
}
Can someone explain how to properly handle the Google ID token and resolve the Drive API authorization issue? Thanks!