Skip to content Skip to sidebar Skip to footer

Accountmanager Auth Token Whithout Clientid And Clientsecret

Hello I'm retrieving a auth token on my app with that code : private String updateToken(boolean invalidateToken, int accountref) { String authToken = 'null'; try {

Solution 1:

I can't see anything wrong with your Android code that gets the token given that you are using the token type "oauth2:https://www.googleapis.com/auth/userinfo.email" as you mentioned in the later update.

I have a test application with very similar code and when using the token type "oauth2:https://www.googleapis.com/auth/userinfo.email" I get a valid token (running Android 2.3.3 on my phone), so it should work.

To make sure the token is valid I log the token, copy it from the log and load https://accounts.google.com/o/oauth2/tokeninfo?access_token=<token> in Chrome. When I do this I get the expected response without any error.

Maybe you could test the same to narrow down where the problem might be?

Update:

This will only work as long as the initial token you got is valid, after it expires you will get an error when you try to use it. My test app stopped working after a while when the token expired. When I changed it to always invalidate the token after I receive it started working again.

For some reason calling am.invalidateAuthToken("com.google", null); doesn't invalidate the token when the token type is "oauth2:https://www.googleapis.com/auth/userinfo.email", so you must specify the token when you want to invalidate it (as your code does).

So if you make sure that you always call your updateToken() method with the invalidateToken parameter set to true this should work for you.

Solution 2:

This API doesn't take clientID or clientSecret as input. The AccountManager will use your saved Google credentials to get you a token by calling any needed Web APIs in the background, or return a cached token, if available. If it returned a token without error, it should be valid. Try it out.

Post a Comment for "Accountmanager Auth Token Whithout Clientid And Clientsecret"