问题描述
我正在开发一个应用程序,在该应用程序中我使用 OAuth 2.0 上传用户 Google 标签中的数据.我能够连接到用户邮件,一段时间后访问令牌过期.
如何使用令牌刷新获取新的访问令牌?
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?
我正在使用 javamail 示例代码进行身份验证并获取访问令牌.我搜索了很多天,但没有找到任何正在运行的代码.我是android新手,所以请提供一些代码或完整的示例代码.
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.
推荐答案
我知道答案了,我想分享给大家,因为很多问题都没有答案.
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.
这篇关于如何使用访问令牌获取 OAuth 2 刷新令牌的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!