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 static class GoogleCredential.Builder extends Credential.Builder
```
Google credential builder.

Implementation is not thread-safe.

## Inheritance

[java.lang.Object](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html) \> com.google.api.client.auth.oauth2.Credential.Builder \> GoogleCredential.Builder

## Inherited Members

com.google.api.client.auth.oauth2.Credential.Builder.addRefreshListener(com.google.api.client.auth.oauth2.CredentialRefreshListener) com.google.api.client.auth.oauth2.Credential.Builder.build() com.google.api.client.auth.oauth2.Credential.Builder.getClientAuthentication() com.google.api.client.auth.oauth2.Credential.Builder.getClock() com.google.api.client.auth.oauth2.Credential.Builder.getJsonFactory() com.google.api.client.auth.oauth2.Credential.Builder.getMethod() com.google.api.client.auth.oauth2.Credential.Builder.getRefreshListeners() com.google.api.client.auth.oauth2.Credential.Builder.getRequestInitializer() com.google.api.client.auth.oauth2.Credential.Builder.getTokenServerUrl() com.google.api.client.auth.oauth2.Credential.Builder.getTransport() com.google.api.client.auth.oauth2.Credential.Builder.setClientAuthentication(com.google.api.client.http.HttpExecuteInterceptor) com.google.api.client.auth.oauth2.Credential.Builder.setClock(com.google.api.client.util.Clock) com.google.api.client.auth.oauth2.Credential.Builder.setJsonFactory(com.google.api.client.json.JsonFactory) com.google.api.client.auth.oauth2.Credential.Builder.setRefreshListeners(java.util.Collection\<com.google.api.client.auth.oauth2.CredentialRefreshListener\>) com.google.api.client.auth.oauth2.Credential.Builder.setRequestInitializer(com.google.api.client.http.HttpRequestInitializer) com.google.api.client.auth.oauth2.Credential.Builder.setTokenServerEncodedUrl(java.lang.String) com.google.api.client.auth.oauth2.Credential.Builder.setTokenServerUrl(com.google.api.client.http.GenericUrl) com.google.api.client.auth.oauth2.Credential.Builder.setTransport(com.google.api.client.http.HttpTransport) [Object.clone()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#clone--) [Object.equals(Object)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#equals-java.lang.Object-) [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.hashCode()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#hashCode--) [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.toString()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#toString--) [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-)

## Constructors

### Builder()

```java
public Builder()
```

## Methods

### addRefreshListener(CredentialRefreshListener refreshListener)

```java
public GoogleCredential.Builder addRefreshListener(CredentialRefreshListener refreshListener)
```

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `refreshListener` | `com.google.api.client.auth.oauth2.CredentialRefreshListener` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `GoogleCredential.Builder` |   |

**Overrides** com.google.api.client.auth.oauth2.Credential.Builder.addRefreshListener(com.google.api.client.auth.oauth2.CredentialRefreshListener)

### build()

```java
public GoogleCredential build()
```

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `GoogleCredential` |   |

**Overrides** com.google.api.client.auth.oauth2.Credential.Builder.build()

### getServiceAccountId()

```java
public final String getServiceAccountId()
```
Returns the service account ID (typically an e-mail address) or `null` for none.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `String` |   |

### getServiceAccountPrivateKey()

```java
public final PrivateKey getServiceAccountPrivateKey()
```
Returns the private key to use with the service account flow or `null` for none.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `PrivateKey` |   |

### getServiceAccountPrivateKeyId()

```java
public final String getServiceAccountPrivateKeyId()
```
Beta   

Returns the id of the private key to use with the service account flow or `null` for
none.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `String` |   |

### getServiceAccountProjectId()

```java
public final String getServiceAccountProjectId()
```
Returns the service account Project ID or `null` for none.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `String` |   |

### getServiceAccountScopes()

```java
public final Collection<String> getServiceAccountScopes()
```
Returns a collection of OAuth scopes to use with the service account flow or `null` for
none.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `Collection<String>` |   |

### getServiceAccountUser()

```java
public final String getServiceAccountUser()
```
Returns the email address of the user the application is trying to impersonate in the service
account flow or `null` for none.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `String` |   |

### setClientAuthentication(HttpExecuteInterceptor clientAuthentication)

```java
public GoogleCredential.Builder setClientAuthentication(HttpExecuteInterceptor clientAuthentication)
```

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

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `GoogleCredential.Builder` |   |

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

### setClientSecrets(GoogleClientSecrets clientSecrets)

```java
public GoogleCredential.Builder setClientSecrets(GoogleClientSecrets clientSecrets)
```
Sets the client secrets.

Overriding is only supported for the purpose of calling the super implementation and
changing the return type, but nothing else.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `clientSecrets` | `GoogleClientSecrets` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `GoogleCredential.Builder` |   |

### setClientSecrets(String clientId, String clientSecret)

```java
public GoogleCredential.Builder setClientSecrets(String clientId, String clientSecret)
```
Sets the client identifier and secret.

Overriding is only supported for the purpose of calling the super implementation and
changing the return type, but nothing else.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `clientId` | `String` |
| `clientSecret` | `String` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `GoogleCredential.Builder` |   |

### setClock(Clock clock)

```java
public GoogleCredential.Builder setClock(Clock clock)
```

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `clock` | `com.google.api.client.util.Clock` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `GoogleCredential.Builder` |   |

**Overrides** com.google.api.client.auth.oauth2.Credential.Builder.setClock(com.google.api.client.util.Clock)

### setJsonFactory(JsonFactory jsonFactory)

```java
public GoogleCredential.Builder setJsonFactory(JsonFactory jsonFactory)
```

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `jsonFactory` | `com.google.api.client.json.JsonFactory` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `GoogleCredential.Builder` |   |

**Overrides** com.google.api.client.auth.oauth2.Credential.Builder.setJsonFactory(com.google.api.client.json.JsonFactory)

### setRefreshListeners(Collection\<CredentialRefreshListener\> refreshListeners)

```java
public GoogleCredential.Builder setRefreshListeners(Collection<CredentialRefreshListener> refreshListeners)
```

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `refreshListeners` | `Collection<com.google.api.client.auth.oauth2.CredentialRefreshListener>` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `GoogleCredential.Builder` |   |

**Overrides** com.google.api.client.auth.oauth2.Credential.Builder.setRefreshListeners(java.util.Collection\<com.google.api.client.auth.oauth2.CredentialRefreshListener\>)

### setRequestInitializer(HttpRequestInitializer requestInitializer)

```java
public GoogleCredential.Builder setRequestInitializer(HttpRequestInitializer requestInitializer)
```

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

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `GoogleCredential.Builder` |   |

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

### setServiceAccountId(String serviceAccountId)

```java
public GoogleCredential.Builder setServiceAccountId(String serviceAccountId)
```
Sets the service account ID (typically an e-mail address) or `null` for none.

Overriding is only supported for the purpose of calling the super implementation and
changing the return type, but nothing else.

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

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `GoogleCredential.Builder` |   |

### setServiceAccountPrivateKey(PrivateKey serviceAccountPrivateKey)

```java
public GoogleCredential.Builder setServiceAccountPrivateKey(PrivateKey serviceAccountPrivateKey)
```
Sets the private key to use with the service account flow or `null` for none.

Overriding is only supported for the purpose of calling the super implementation and
changing the return type, but nothing else.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `serviceAccountPrivateKey` | `PrivateKey` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `GoogleCredential.Builder` |   |

### setServiceAccountPrivateKeyFromP12File(File p12File)

```java
public GoogleCredential.Builder setServiceAccountPrivateKeyFromP12File(File p12File)
```
Sets the private key to use with the service account flow or `null` for none.

Overriding is only supported for the purpose of calling the super implementation and
changing the return type, but nothing else.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `p12File` | `File` p12 file object |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `GoogleCredential.Builder` |   |

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

### setServiceAccountPrivateKeyFromP12File(InputStream p12FileInputStream)

```java
public GoogleCredential.Builder setServiceAccountPrivateKeyFromP12File(InputStream p12FileInputStream)
```
Sets the private key to use with the service account flow or `null` for none.

Overriding is only supported for the purpose of calling the super implementation and
changing the return type, but nothing else.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `p12FileInputStream` | `InputStream` input stream to the p12 file. This file is closed at the end of this method in a finally block. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `GoogleCredential.Builder` |   |

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

### setServiceAccountPrivateKeyFromPemFile(File pemFile)

```java
public GoogleCredential.Builder setServiceAccountPrivateKeyFromPemFile(File pemFile)
```
Beta   

Sets the private key to use with the service account flow or `null` for none.

Overriding is only supported for the purpose of calling the super implementation and
changing the return type, but nothing else.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `pemFile` | `File` input stream to the PEM file (closed at the end of this method in a finally block) |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `GoogleCredential.Builder` |   |

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

### setServiceAccountPrivateKeyId(String serviceAccountPrivateKeyId)

```java
public GoogleCredential.Builder setServiceAccountPrivateKeyId(String serviceAccountPrivateKeyId)
```
Beta   

Sets the id of the private key to use with the service account flow or `null` for none.

Overriding is only supported for the purpose of calling the super implementation and
changing the return type, but nothing else.

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

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `GoogleCredential.Builder` |   |

### setServiceAccountProjectId(String serviceAccountProjectId)

```java
public GoogleCredential.Builder setServiceAccountProjectId(String serviceAccountProjectId)
```
Sets the service account Project ID or `null` for none.

Overriding is only supported for the purpose of calling the super implementation and
changing the return type, but nothing else.

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

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `GoogleCredential.Builder` |   |

### setServiceAccountScopes(Collection\<String\> serviceAccountScopes)

```java
public GoogleCredential.Builder setServiceAccountScopes(Collection<String> serviceAccountScopes)
```
Sets the space-separated OAuth scopes to use with the service account flow or `null`
for none.

Overriding is only supported for the purpose of calling the super implementation and
changing the return type, but nothing else.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `serviceAccountScopes` | `Collection<String>` collection of scopes to be joined by a space separator (or a single value containing multiple space-separated scopes) |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `GoogleCredential.Builder` |   |

### setServiceAccountUser(String serviceAccountUser)

```java
public GoogleCredential.Builder setServiceAccountUser(String serviceAccountUser)
```
Sets the email address of the user the application is trying to impersonate in the service
account flow or `null` for none.

Overriding is only supported for the purpose of calling the super implementation and
changing the return type, but nothing else.

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

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `GoogleCredential.Builder` |   |

### setTokenServerEncodedUrl(String tokenServerEncodedUrl)

```java
public GoogleCredential.Builder setTokenServerEncodedUrl(String tokenServerEncodedUrl)
```

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

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `GoogleCredential.Builder` |   |

**Overrides** com.google.api.client.auth.oauth2.Credential.Builder.setTokenServerEncodedUrl(java.lang.String)

### setTokenServerUrl(GenericUrl tokenServerUrl)

```java
public GoogleCredential.Builder setTokenServerUrl(GenericUrl tokenServerUrl)
```

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

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `GoogleCredential.Builder` |   |

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

### setTransport(HttpTransport transport)

```java
public GoogleCredential.Builder setTransport(HttpTransport transport)
```

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `transport` | `com.google.api.client.http.HttpTransport` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `GoogleCredential.Builder` |   |

**Overrides** com.google.api.client.auth.oauth2.Credential.Builder.setTransport(com.google.api.client.http.HttpTransport)