I have managed to sign in my app to my google drive account. However, when trying to retrieve a drive service api, I was unable to retrieve my credentials and set them to get the drive. Upon further inspection, I realise that the GoogleSignInAccount class that I created looks different from the GoogleSignInAccount that is stated in the documentation found at https://developers.google.com/android/reference/com/google/android/gms/auth/api/signin/GoogleSignInAccount
It doesn't have methods like getAcccount() or getemail(). Instead, the class instance in my app has weird attributes seen below:
As result my code results in a null exception invoked. googleAccount is my GoogleSignInAccount class instance.
Running googleAccount.account and googleAccount.getAccount() both returns null.
Below is my full code if needed:
fun getDriveService() : Drive?{
GoogleSignIn.getLastSignedInAccount(this)?.let { googleAccount ->
val credential = GoogleAccountCredential.usingOAuth2(
this, listOf(DriveScopes.DRIVE_FILE)
)
println(googleAccount)
credential.selectedAccount = googleAccount.account!!
return Drive.Builder(
AndroidHttp.newCompatibleTransport(),
JacksonFactory.getDefaultInstance(),
credential
)
.setApplicationName(getString(R.string.app_name))
.build()
}
return null
}
