问题
I am developing an app in which i am using OAuth 2.0 to upload data in user Google label. I am able to connect to the users mail and after some time access token expires.
How to get new access token using Token refresher?
I am using javamail sample code to authenticate and get access token. I am searching it from many days but did not found any running code. I am new to android, so please provide some code or complete sample code.
回答1:
I got the answer now i want to share to all of you because many questions are unanswered.
to get a new token first you have to invalidate the token using below code
accountManager.invalidateAuthToken("com.google", token);
after invalidating the token you require to get a new Token, below code provides a new Token
String newToken = AccountManager.get(this).getAuthToken(new Account(account, "com.google"),
AUTH_TOKEN_TYPE, true, null, null).getResult().getString(AccountManager.KEY_AUTHTOKEN);
now you can use your new token to authenticate and login.
来源:https://stackoverflow.com/questions/18572088/how-to-get-oauth-2-refresh-token-using-access-token