使用 Java 从刷新令牌中获取访问令牌 [英] Fetching access token from refresh token using Java

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

问题描述

我使用此处给出的示例程序从授权代码中获取了刷新令牌和访问令牌https://developers.google.com/drive/credentials#retrieve_oauth_20_credentials

I got the refresh token and access token from the authorization code by using the sample program given here https://developers.google.com/drive/credentials#retrieve_oauth_20_credentials

但是没有示例程序可以从刷新令牌中获取访问令牌,即当我们没有授权码时.任何指针?有没有办法只使用刷新令牌和访问令牌来实例化驱动服务对象?

But there is no sample program to get the access token from refresh token i.e., when we dont have authorization code. Any pointers? Is there any way to Instantiate a drive service object using only refresh token and access token?

推荐答案

DrEdit Java 示例有一个关于如何从 Google App Engine 数据存储中检索存储凭据的示例.

The DrEdit Java sample has an example on how to retrieve stored Credentials from the Google App Engine Datastore.

如果使用其他类型的凭据存储,您可以使用以下代码使用存储的令牌实例化新的 OAuth 2.0 凭据:

If using another type of credentials store, you can use the following code to instantiate new OAuth 2.0 Credentials using stored tokens:

GoogleCredential credentials = new GoogleCredential.Builder()
    .setClientSecrets(CLIENT_ID, CLIENT_SECRET)
    .setJsonFactory(jsonFactory).setTransport(transport).build()
    .setRefreshToken("<REFRESH_TOKEN>").setAccessToken("<ACCESS_TOKEN>");

更正了代码中的错字.

这篇关于使用 Java 从刷新令牌中获取访问令牌的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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