How to get OAuth 2 refresh token using access token

风流意气都作罢 提交于 2019-12-09 00:18:55

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!