且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用 Java 从刷新令牌中获取访问令牌

更新时间:2023-02-15 08:15:48

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>");

更正了代码中的错字.