如何使用访问令牌获取 OAuth 2 刷新令牌 [英] How to get OAuth 2 refresh token using access token

查看:51
本文介绍了如何使用访问令牌获取 OAuth 2 刷新令牌的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个应用程序,在该应用程序中我使用 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 刷新令牌的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆