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

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

问题描述

我开发一个应用程序中,我使用OAuth 2.0上传用户谷歌标签数据。我能够连接到用户的邮件和一段时间的访问令牌到期之后。
如何使用令牌进修获得新的访问令牌?

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样品code认证,并获得访问令牌。我从许多天寻找,但没有发现任何正在运行的code。我是新来的机器人,所以请提供一些code或完整的示例code。

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.

先得到一个新的令牌,你必须使用以下code令牌无效

to get a new token first you have to invalidate the token using below code

accountManager.invalidateAuthToken("com.google", token);

无效您需要得到一个新的令牌令牌,低于code后,提供了一个新的令牌

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天全站免登陆