Class GoogleRefreshTokenRequest (1.35.1)

public class GoogleRefreshTokenRequest extends RefreshTokenRequest

Google-specific implementation of the OAuth 2.0 request to refresh an access token using a refresh token as specified in Refreshing an Access Token.

Use GoogleCredential to access protected resources from the resource server using the TokenResponse returned by #execute(). On error, it will instead throw TokenResponseException.

Sample usage:


 static void refreshAccessToken() throws IOException {
   try {
     TokenResponse response = new GoogleRefreshTokenRequest(
         new NetHttpTransport(), new GsonFactory(),
         "tGzv3JOkF0XG5Qx2TlKWIA", "s6BhdRkqt3",
 "7Fjfp0ZBr1KtDRbnfVdmIw").execute();
     System.out.println("Access token: " + response.getAccessToken());
   } catch (TokenResponseException e) {
     if (e.getDetails() != null) {
       System.err.println("Error: " + e.getDetails().getError());
       if (e.getDetails().getErrorDescription() != null) {
         System.err.println(e.getDetails().getErrorDescription());
       }
       if (e.getDetails().getErrorUri() != null) {
         System.err.println(e.getDetails().getErrorUri());
       }
     } else {
       System.err.println(e.getMessage());
     }
   }
 }
 

Implementation is not thread-safe.

Inheritance

Object > java.util.AbstractMap > com.google.api.client.util.GenericData > com.google.api.client.auth.oauth2.TokenRequest > com.google.api.client.auth.oauth2.RefreshTokenRequest > GoogleRefreshTokenRequest

Constructors

GoogleRefreshTokenRequest(HttpTransport transport, JsonFactory jsonFactory, String refreshToken, String clientId, String clientSecret)

public GoogleRefreshTokenRequest(HttpTransport transport, JsonFactory jsonFactory, String refreshToken, String clientId, String clientSecret)
Parameters
NameDescription
transportcom.google.api.client.http.HttpTransport

HTTP transport

jsonFactorycom.google.api.client.json.JsonFactory

JSON factory

refreshTokenString

refresh token issued to the client

clientIdString

client identifier issued to the client during the registration process

clientSecretString

client secret

Methods

execute()

public GoogleTokenResponse execute()
Returns
TypeDescription
GoogleTokenResponse
Overrides
com.google.api.client.auth.oauth2.TokenRequest.execute()
Exceptions
TypeDescription
IOException

set(String fieldName, Object value)

public GoogleRefreshTokenRequest set(String fieldName, Object value)
Parameters
NameDescription
fieldNameString
valueObject
Returns
TypeDescription
GoogleRefreshTokenRequest
Overrides
com.google.api.client.auth.oauth2.RefreshTokenRequest.set(java.lang.String,java.lang.Object)

setClientAuthentication(HttpExecuteInterceptor clientAuthentication)

public GoogleRefreshTokenRequest setClientAuthentication(HttpExecuteInterceptor clientAuthentication)
Parameter
NameDescription
clientAuthenticationcom.google.api.client.http.HttpExecuteInterceptor
Returns
TypeDescription
GoogleRefreshTokenRequest
Overrides
com.google.api.client.auth.oauth2.RefreshTokenRequest.setClientAuthentication(com.google.api.client.http.HttpExecuteInterceptor)

setGrantType(String grantType)

public GoogleRefreshTokenRequest setGrantType(String grantType)
Parameter
NameDescription
grantTypeString
Returns
TypeDescription
GoogleRefreshTokenRequest
Overrides
com.google.api.client.auth.oauth2.RefreshTokenRequest.setGrantType(java.lang.String)

setRefreshToken(String refreshToken)

public GoogleRefreshTokenRequest setRefreshToken(String refreshToken)
Parameter
NameDescription
refreshTokenString
Returns
TypeDescription
GoogleRefreshTokenRequest
Overrides
com.google.api.client.auth.oauth2.RefreshTokenRequest.setRefreshToken(java.lang.String)

setRequestInitializer(HttpRequestInitializer requestInitializer)

public GoogleRefreshTokenRequest setRequestInitializer(HttpRequestInitializer requestInitializer)
Parameter
NameDescription
requestInitializercom.google.api.client.http.HttpRequestInitializer
Returns
TypeDescription
GoogleRefreshTokenRequest
Overrides
com.google.api.client.auth.oauth2.RefreshTokenRequest.setRequestInitializer(com.google.api.client.http.HttpRequestInitializer)

setScopes(Collection<String> scopes)

public GoogleRefreshTokenRequest setScopes(Collection<String> scopes)
Parameter
NameDescription
scopesCollection<String>
Returns
TypeDescription
GoogleRefreshTokenRequest
Overrides
com.google.api.client.auth.oauth2.RefreshTokenRequest.setScopes(java.util.Collection<java.lang.String>)

setTokenServerUrl(GenericUrl tokenServerUrl)

public GoogleRefreshTokenRequest setTokenServerUrl(GenericUrl tokenServerUrl)
Parameter
NameDescription
tokenServerUrlcom.google.api.client.http.GenericUrl
Returns
TypeDescription
GoogleRefreshTokenRequest
Overrides
com.google.api.client.auth.oauth2.RefreshTokenRequest.setTokenServerUrl(com.google.api.client.http.GenericUrl)