2.9.3 (latest) 2.9.2 2.8.1 2.7.2 2.6.0 2.5.1 2.4.1 2.1.2 2.0.1 1.35.2 1.34.1 1.33.4

```java
public class GoogleAuthorizationCodeTokenRequest extends AuthorizationCodeTokenRequest
```
Google-specific implementation of the OAuth 2.0 request for an access token based on an
authorization code (as specified in [Using OAuth 2.0 for Web Server
Applications](https://developers.google.com/identity/protocols/OAuth2WebServer)).

Use [GoogleCredential](https://docs.cloud.google.com/java/docs/reference/google-api-client/latest/com.google.api.client.googleapis.auth.oauth2.GoogleCredential.md.txt) to access protected resources from the resource server using the
TokenResponse returned by [#execute()](https://docs.cloud.google.com/java/docs/reference/google-api-client/latest/com.google.api.client.googleapis.auth.oauth2.GoogleAuthorizationCodeTokenRequest.md.txt#com_google_api_client_googleapis_auth_oauth2_GoogleAuthorizationCodeTokenRequest_execute__). On error, it will instead throw TokenResponseException.

Sample usage:

```java

 static void requestAccessToken() throws IOException {
   try {
     GoogleTokenResponse response = new GoogleAuthorizationCodeTokenRequest(
         new NetHttpTransport(), new GsonFactory(),
         "812741506391.apps.googleusercontent.com", "{client_secret}",
         "4/P7q7W91a-oMsCeLvIaQm6bTrgtp7", "https://oauth2-login-demo.appspot.com/code")
         .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](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html) \> java.util.AbstractMap \> com.google.api.client.util.GenericData \> com.google.api.client.auth.oauth2.TokenRequest \> com.google.api.client.auth.oauth2.AuthorizationCodeTokenRequest \> GoogleAuthorizationCodeTokenRequest

## Inherited Members

com.google.api.client.auth.oauth2.AuthorizationCodeTokenRequest.getCode() com.google.api.client.auth.oauth2.AuthorizationCodeTokenRequest.getRedirectUri() com.google.api.client.auth.oauth2.AuthorizationCodeTokenRequest.set(java.lang.String,java.lang.Object) com.google.api.client.auth.oauth2.AuthorizationCodeTokenRequest.setClientAuthentication(com.google.api.client.http.HttpExecuteInterceptor) com.google.api.client.auth.oauth2.AuthorizationCodeTokenRequest.setCode(java.lang.String) com.google.api.client.auth.oauth2.AuthorizationCodeTokenRequest.setGrantType(java.lang.String) com.google.api.client.auth.oauth2.AuthorizationCodeTokenRequest.setRedirectUri(java.lang.String) com.google.api.client.auth.oauth2.AuthorizationCodeTokenRequest.setRequestInitializer(com.google.api.client.http.HttpRequestInitializer) com.google.api.client.auth.oauth2.AuthorizationCodeTokenRequest.setResponseClass(java.lang.Class\<? extends com.google.api.client.auth.oauth2.TokenResponse\>) com.google.api.client.auth.oauth2.AuthorizationCodeTokenRequest.setScopes(java.util.Collection\<java.lang.String\>) com.google.api.client.auth.oauth2.AuthorizationCodeTokenRequest.setTokenServerUrl(com.google.api.client.http.GenericUrl) com.google.api.client.auth.oauth2.TokenRequest.execute() com.google.api.client.auth.oauth2.TokenRequest.executeUnparsed() com.google.api.client.auth.oauth2.TokenRequest.getClientAuthentication() com.google.api.client.auth.oauth2.TokenRequest.getGrantType() com.google.api.client.auth.oauth2.TokenRequest.getJsonFactory() com.google.api.client.auth.oauth2.TokenRequest.getRequestInitializer() com.google.api.client.auth.oauth2.TokenRequest.getResponseClass() com.google.api.client.auth.oauth2.TokenRequest.getScopes() com.google.api.client.auth.oauth2.TokenRequest.getTokenServerUrl() com.google.api.client.auth.oauth2.TokenRequest.getTransport() com.google.api.client.util.GenericData.clone() com.google.api.client.util.GenericData.entrySet() com.google.api.client.util.GenericData.equals(java.lang.Object) com.google.api.client.util.GenericData.get(java.lang.Object) com.google.api.client.util.GenericData.getClassInfo() com.google.api.client.util.GenericData.getUnknownKeys() com.google.api.client.util.GenericData.hashCode() com.google.api.client.util.GenericData.put(java.lang.String,java.lang.Object) com.google.api.client.util.GenericData.putAll(java.util.Map\<? extends java.lang.String,?\>) com.google.api.client.util.GenericData.remove(java.lang.Object) com.google.api.client.util.GenericData.setUnknownKeys(java.util.Map\<java.lang.String,java.lang.Object\>) com.google.api.client.util.GenericData.toString() [Object.finalize()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#finalize--) [Object.getClass()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#getClass--) [Object.notify()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#notify--) [Object.notifyAll()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#notifyAll--) [Object.wait()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait--) [Object.wait(long)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait-long-) [Object.wait(long,int)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait-long-int-) [AbstractMap.clear()](https://docs.oracle.com/javase/8/docs/api/java/util/AbstractMap.html#clear--) [AbstractMap.containsKey(Object)](https://docs.oracle.com/javase/8/docs/api/java/util/AbstractMap.html#containsKey-java.lang.Object-) [AbstractMap.containsValue(Object)](https://docs.oracle.com/javase/8/docs/api/java/util/AbstractMap.html#containsValue-java.lang.Object-) [AbstractMap.isEmpty()](https://docs.oracle.com/javase/8/docs/api/java/util/AbstractMap.html#isEmpty--) [AbstractMap.keySet()](https://docs.oracle.com/javase/8/docs/api/java/util/AbstractMap.html#keySet--) [AbstractMap.put(K,V)](https://docs.oracle.com/javase/8/docs/api/java/util/AbstractMap.html#put-K-V-) [AbstractMap.putAll(Map\<? extends K,? extends V\>)](https://docs.oracle.com/javase/8/docs/api/java/util/AbstractMap.html#putAll-java.util.Map<? extends K-? extends V>-) [AbstractMap.size()](https://docs.oracle.com/javase/8/docs/api/java/util/AbstractMap.html#size--) [AbstractMap.values()](https://docs.oracle.com/javase/8/docs/api/java/util/AbstractMap.html#values--)

## Constructors

### GoogleAuthorizationCodeTokenRequest(HttpTransport transport, JsonFactory jsonFactory, String clientId, String clientSecret, String code, String redirectUri)

```java
public GoogleAuthorizationCodeTokenRequest(HttpTransport transport, JsonFactory jsonFactory, String clientId, String clientSecret, String code, String redirectUri)
```

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `transport` | `com.google.api.client.http.HttpTransport` HTTP transport |
| `jsonFactory` | `com.google.api.client.json.JsonFactory` JSON factory |
| `clientId` | `String` client identifier issued to the client during the registration process |
| `clientSecret` | `String` client secret |
| `code` | `String` authorization code generated by the authorization server |
| `redirectUri` | `String` redirect URL parameter matching the redirect URL parameter in the authorization request (see [#setRedirectUri(String)](https://docs.cloud.google.com/java/docs/reference/google-api-client/latest/com.google.api.client.googleapis.auth.oauth2.GoogleAuthorizationCodeTokenRequest.md.txt#com_google_api_client_googleapis_auth_oauth2_GoogleAuthorizationCodeTokenRequest_setRedirectUri_java_lang_String_) |

### GoogleAuthorizationCodeTokenRequest(HttpTransport transport, JsonFactory jsonFactory, String tokenServerEncodedUrl, String clientId, String clientSecret, String code, String redirectUri)

```java
public GoogleAuthorizationCodeTokenRequest(HttpTransport transport, JsonFactory jsonFactory, String tokenServerEncodedUrl, String clientId, String clientSecret, String code, String redirectUri)
```

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `transport` | `com.google.api.client.http.HttpTransport` HTTP transport |
| `jsonFactory` | `com.google.api.client.json.JsonFactory` JSON factory |
| `tokenServerEncodedUrl` | `String` token server encoded URL |
| `clientId` | `String` client identifier issued to the client during the registration process |
| `clientSecret` | `String` client secret |
| `code` | `String` authorization code generated by the authorization server |
| `redirectUri` | `String` redirect URL parameter matching the redirect URL parameter in the authorization request (see [#setRedirectUri(String)](https://docs.cloud.google.com/java/docs/reference/google-api-client/latest/com.google.api.client.googleapis.auth.oauth2.GoogleAuthorizationCodeTokenRequest.md.txt#com_google_api_client_googleapis_auth_oauth2_GoogleAuthorizationCodeTokenRequest_setRedirectUri_java_lang_String_) |

## Methods

### execute()

```java
public GoogleTokenResponse execute()
```

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `GoogleTokenResponse` |   |

**Overrides** com.google.api.client.auth.oauth2.TokenRequest.execute()

| **Exceptions** ||
|---|---|
| **Type** | **Description** |
| `IOException` |   |

### set(String fieldName, Object value)

```java
public GoogleAuthorizationCodeTokenRequest set(String fieldName, Object value)
```

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `fieldName` | `String` |
| `value` | `Object` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `GoogleAuthorizationCodeTokenRequest` |   |

**Overrides** com.google.api.client.auth.oauth2.AuthorizationCodeTokenRequest.set(java.lang.String,java.lang.Object)

### setClientAuthentication(HttpExecuteInterceptor clientAuthentication)

```java
public GoogleAuthorizationCodeTokenRequest setClientAuthentication(HttpExecuteInterceptor clientAuthentication)
```

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `clientAuthentication` | `com.google.api.client.http.HttpExecuteInterceptor` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `GoogleAuthorizationCodeTokenRequest` |   |

**Overrides** com.google.api.client.auth.oauth2.AuthorizationCodeTokenRequest.setClientAuthentication(com.google.api.client.http.HttpExecuteInterceptor)

### setCode(String code)

```java
public GoogleAuthorizationCodeTokenRequest setCode(String code)
```

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `code` | `String` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `GoogleAuthorizationCodeTokenRequest` |   |

**Overrides** com.google.api.client.auth.oauth2.AuthorizationCodeTokenRequest.setCode(java.lang.String)

### setGrantType(String grantType)

```java
public GoogleAuthorizationCodeTokenRequest setGrantType(String grantType)
```

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `grantType` | `String` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `GoogleAuthorizationCodeTokenRequest` |   |

**Overrides** com.google.api.client.auth.oauth2.AuthorizationCodeTokenRequest.setGrantType(java.lang.String)

### setRedirectUri(String redirectUri)

```java
public GoogleAuthorizationCodeTokenRequest setRedirectUri(String redirectUri)
```

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `redirectUri` | `String` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `GoogleAuthorizationCodeTokenRequest` |   |

**Overrides** com.google.api.client.auth.oauth2.AuthorizationCodeTokenRequest.setRedirectUri(java.lang.String)

### setRequestInitializer(HttpRequestInitializer requestInitializer)

```java
public GoogleAuthorizationCodeTokenRequest setRequestInitializer(HttpRequestInitializer requestInitializer)
```

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `requestInitializer` | `com.google.api.client.http.HttpRequestInitializer` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `GoogleAuthorizationCodeTokenRequest` |   |

**Overrides** com.google.api.client.auth.oauth2.AuthorizationCodeTokenRequest.setRequestInitializer(com.google.api.client.http.HttpRequestInitializer)

### setScopes(Collection\<String\> scopes)

```java
public GoogleAuthorizationCodeTokenRequest setScopes(Collection<String> scopes)
```

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `scopes` | `Collection<String>` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `GoogleAuthorizationCodeTokenRequest` |   |

**Overrides** com.google.api.client.auth.oauth2.AuthorizationCodeTokenRequest.setScopes(java.util.Collection\<java.lang.String\>)

### setTokenServerUrl(GenericUrl tokenServerUrl)

```java
public GoogleAuthorizationCodeTokenRequest setTokenServerUrl(GenericUrl tokenServerUrl)
```

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `tokenServerUrl` | `com.google.api.client.http.GenericUrl` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `GoogleAuthorizationCodeTokenRequest` |   |

**Overrides** com.google.api.client.auth.oauth2.AuthorizationCodeTokenRequest.setTokenServerUrl(com.google.api.client.http.GenericUrl)