I am trying to implement Google rest api for Drive V3 in Android.
But I am getting authError
{
"error":{
"errors":[
{
"domain":"global",
"reason":"authError",
"message":"Invalid Credentials",
"locationType":"header",
"location":"Authorization"
}
],
"code":401,
"message":"Invalid Credentials"
}
}
I use AccountManager to get token from user, and I think it access the wrong console account.
How does it know what account to access?
This is my AccountManager code, I successfully get user token. Also I invalidate it before with AccountManager.invalidateAuthToken
Bundle options = new Bundle();
options.putString(AccountManager.KEY_ANDROID_PACKAGE_NAME, context.getPackageName());
accountManager.getAuthToken(account, scope, options, context,
callback, null);
As per the Account Manager docs for [getAuthToken]( http://developer.android.com/reference/android/accounts/AccountManager.html#getAuthToken(android.accounts.Account , java.lang.String, android.os.Bundle, android.app.Activity, android.accounts.AccountManagerCallback, android.os.Handler)):
Gets an auth token of the specified type for a particular account, prompting the user for credentials if necessary . This method is intended for applications running in the foreground where it makes sense to ask the user directly for a password.
If a previously generated auth token is cached for this account and type, then it is returned . Otherwise, if a saved password is available, it is sent to the server to generate a new auth token. Otherwise, the user is prompted to enter a password.
It seems that it may depend on the value of your account
variable that you are passing in the getAuthToken()
.
You probably already have this in, but gonna included in for the community, did you include the USE_CREDENTIALS
permission as mentioned in the docs:
NOTE : If targeting your app to work on API level 22 and before, USE_CREDENTIALS permission is needed for those platforms.
Hope this helps. Good luck. :)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.