com.google.api.client.googleapis.auth.oauth2
Class GoogleRefreshTokenRequest

java.lang.Object
  extended by java.util.AbstractMap<String,Object>
      extended by com.google.api.client.util.GenericData
          extended by com.google.api.client.auth.oauth2.TokenRequest
              extended by com.google.api.client.auth.oauth2.RefreshTokenRequest
                  extended by com.google.api.client.googleapis.auth.oauth2.GoogleRefreshTokenRequest
All Implemented Interfaces:
Cloneable, Map<String,Object>

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 JacksonFactory(),
              "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.

Since:
1.7
Author:
Yaniv Inbar

Nested Class Summary
 
Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K,V>
 
Nested classes/interfaces inherited from interface java.util.Map
Map.Entry<K,V>
 
Constructor Summary
GoogleRefreshTokenRequest(HttpTransport transport, JsonFactory jsonFactory, String refreshToken, String clientId, String clientSecret)
           
 
Method Summary
 GoogleTokenResponse execute()
           
 GoogleRefreshTokenRequest setClientAuthentication(HttpExecuteInterceptor clientAuthentication)
           
 GoogleRefreshTokenRequest setGrantType(String grantType)
           
 GoogleRefreshTokenRequest setRefreshToken(String refreshToken)
           
 GoogleRefreshTokenRequest setRequestInitializer(HttpRequestInitializer requestInitializer)
           
 GoogleRefreshTokenRequest setScopes(Iterable<String> scopes)
           
 GoogleRefreshTokenRequest setScopes(String... scopes)
           
 GoogleRefreshTokenRequest setTokenServerUrl(GenericUrl tokenServerUrl)
           
 
Methods inherited from class com.google.api.client.auth.oauth2.RefreshTokenRequest
getRefreshToken
 
Methods inherited from class com.google.api.client.auth.oauth2.TokenRequest
executeUnparsed, getClientAuthentication, getGrantType, getJsonFactory, getRequestInitializer, getScopes, getTokenServerUrl, getTransport
 
Methods inherited from class com.google.api.client.util.GenericData
clone, entrySet, get, getUnknownKeys, put, putAll, remove, set, setUnknownKeys
 
Methods inherited from class java.util.AbstractMap
clear, containsKey, containsValue, equals, hashCode, isEmpty, keySet, size, toString, values
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

GoogleRefreshTokenRequest

public GoogleRefreshTokenRequest(HttpTransport transport,
                                 JsonFactory jsonFactory,
                                 String refreshToken,
                                 String clientId,
                                 String clientSecret)
Parameters:
transport - HTTP transport
jsonFactory - JSON factory
refreshToken - refresh token issued to the client
clientId - client identifier issued to the client during the registration process
clientSecret - client secret
Method Detail

setRequestInitializer

public GoogleRefreshTokenRequest setRequestInitializer(HttpRequestInitializer requestInitializer)
Overrides:
setRequestInitializer in class RefreshTokenRequest

setTokenServerUrl

public GoogleRefreshTokenRequest setTokenServerUrl(GenericUrl tokenServerUrl)
Overrides:
setTokenServerUrl in class RefreshTokenRequest

setScopes

public GoogleRefreshTokenRequest setScopes(String... scopes)
Overrides:
setScopes in class RefreshTokenRequest

setScopes

public GoogleRefreshTokenRequest setScopes(Iterable<String> scopes)
Overrides:
setScopes in class RefreshTokenRequest

setGrantType

public GoogleRefreshTokenRequest setGrantType(String grantType)
Overrides:
setGrantType in class RefreshTokenRequest

setClientAuthentication

public GoogleRefreshTokenRequest setClientAuthentication(HttpExecuteInterceptor clientAuthentication)
Overrides:
setClientAuthentication in class RefreshTokenRequest

setRefreshToken

public GoogleRefreshTokenRequest setRefreshToken(String refreshToken)
Overrides:
setRefreshToken in class RefreshTokenRequest

execute

public GoogleTokenResponse execute()
                            throws IOException
Overrides:
execute in class TokenRequest
Throws:
IOException


Copyright © 2010-2012 Google. All Rights Reserved.