2.9.1 (latest) 2.9.0 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

    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()

    public Builder()

## Methods

### addRefreshListener(CredentialRefreshListener refreshListener)

    public GoogleCredential.Builder addRefreshListener(CredentialRefreshListener refreshListener)

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

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-api-client/latest/com.google.api.client.googleapis.auth.oauth2.GoogleCredential.Builder` |   |

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

### build()

    public GoogleCredential build()

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-api-client/latest/com.google.api.client.googleapis.auth.oauth2.GoogleCredential` |   |

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

### getServiceAccountId()

    public final String getServiceAccountId()

Returns the service account ID (typically an e-mail address) or `null` for none.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` |   |

### getServiceAccountPrivateKey()

    public final PrivateKey getServiceAccountPrivateKey()

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

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/security/PrivateKey.html` |   |

### getServiceAccountPrivateKeyId()

    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** |
| `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` |   |

### getServiceAccountProjectId()

    public final String getServiceAccountProjectId()

Returns the service account Project ID or `null` for none.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` |   |

### getServiceAccountScopes()

    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** |
| `https://docs.oracle.com/javase/8/docs/api/java/util/Collection.html<https://docs.oracle.com/javase/8/docs/api/java/lang/String.html>` |   |

### getServiceAccountUser()

    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** |
| `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` |   |

### setClientAuthentication(HttpExecuteInterceptor clientAuthentication)

    public GoogleCredential.Builder setClientAuthentication(HttpExecuteInterceptor clientAuthentication)

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

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-api-client/latest/com.google.api.client.googleapis.auth.oauth2.GoogleCredential.Builder` |   |

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

### setClientSecrets(GoogleClientSecrets clientSecrets)

    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` | `https://docs.cloud.google.com/java/docs/reference/google-api-client/latest/com.google.api.client.googleapis.auth.oauth2.GoogleClientSecrets` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-api-client/latest/com.google.api.client.googleapis.auth.oauth2.GoogleCredential.Builder` |   |

### setClientSecrets(String clientId, String clientSecret)

    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` | `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` |
| `clientSecret` | `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-api-client/latest/com.google.api.client.googleapis.auth.oauth2.GoogleCredential.Builder` |   |

### setClock(Clock clock)

    public GoogleCredential.Builder setClock(Clock clock)

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

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-api-client/latest/com.google.api.client.googleapis.auth.oauth2.GoogleCredential.Builder` |   |

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

### setJsonFactory(JsonFactory jsonFactory)

    public GoogleCredential.Builder setJsonFactory(JsonFactory jsonFactory)

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

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-api-client/latest/com.google.api.client.googleapis.auth.oauth2.GoogleCredential.Builder` |   |

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

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

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

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `refreshListeners` | `https://docs.oracle.com/javase/8/docs/api/java/util/Collection.html<com.google.api.client.auth.oauth2.CredentialRefreshListener>` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-api-client/latest/com.google.api.client.googleapis.auth.oauth2.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)

    public GoogleCredential.Builder setRequestInitializer(HttpRequestInitializer requestInitializer)

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

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-api-client/latest/com.google.api.client.googleapis.auth.oauth2.GoogleCredential.Builder` |   |

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

### setServiceAccountId(String serviceAccountId)

    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` | `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-api-client/latest/com.google.api.client.googleapis.auth.oauth2.GoogleCredential.Builder` |   |

### setServiceAccountPrivateKey(PrivateKey serviceAccountPrivateKey)

    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` | `https://docs.oracle.com/javase/8/docs/api/java/security/PrivateKey.html` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-api-client/latest/com.google.api.client.googleapis.auth.oauth2.GoogleCredential.Builder` |   |

### setServiceAccountPrivateKeyFromP12File(File p12File)

    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` | `https://docs.oracle.com/javase/8/docs/api/java/io/File.html` p12 file object |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-api-client/latest/com.google.api.client.googleapis.auth.oauth2.GoogleCredential.Builder` |   |

| **Exceptions** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/security/GeneralSecurityException.html` |   |
| `https://docs.oracle.com/javase/8/docs/api/java/io/IOException.html` |   |

### setServiceAccountPrivateKeyFromP12File(InputStream p12FileInputStream)

    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` | `https://docs.oracle.com/javase/8/docs/api/java/io/InputStream.html` input stream to the p12 file. This file is closed at the end of this method in a finally block. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-api-client/latest/com.google.api.client.googleapis.auth.oauth2.GoogleCredential.Builder` |   |

| **Exceptions** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/security/GeneralSecurityException.html` |   |
| `https://docs.oracle.com/javase/8/docs/api/java/io/IOException.html` |   |

### setServiceAccountPrivateKeyFromPemFile(File pemFile)

    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` | `https://docs.oracle.com/javase/8/docs/api/java/io/File.html` input stream to the PEM file (closed at the end of this method in a finally block) |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-api-client/latest/com.google.api.client.googleapis.auth.oauth2.GoogleCredential.Builder` |   |

| **Exceptions** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/security/GeneralSecurityException.html` |   |
| `https://docs.oracle.com/javase/8/docs/api/java/io/IOException.html` |   |

### setServiceAccountPrivateKeyId(String serviceAccountPrivateKeyId)

    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` | `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-api-client/latest/com.google.api.client.googleapis.auth.oauth2.GoogleCredential.Builder` |   |

### setServiceAccountProjectId(String serviceAccountProjectId)

    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` | `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-api-client/latest/com.google.api.client.googleapis.auth.oauth2.GoogleCredential.Builder` |   |

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

    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` | `https://docs.oracle.com/javase/8/docs/api/java/util/Collection.html<https://docs.oracle.com/javase/8/docs/api/java/lang/String.html>` collection of scopes to be joined by a space separator (or a single value containing multiple space-separated scopes) |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-api-client/latest/com.google.api.client.googleapis.auth.oauth2.GoogleCredential.Builder` |   |

### setServiceAccountUser(String serviceAccountUser)

    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` | `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-api-client/latest/com.google.api.client.googleapis.auth.oauth2.GoogleCredential.Builder` |   |

### setTokenServerEncodedUrl(String tokenServerEncodedUrl)

    public GoogleCredential.Builder setTokenServerEncodedUrl(String tokenServerEncodedUrl)

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `tokenServerEncodedUrl` | `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-api-client/latest/com.google.api.client.googleapis.auth.oauth2.GoogleCredential.Builder` |   |

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

### setTokenServerUrl(GenericUrl tokenServerUrl)

    public GoogleCredential.Builder setTokenServerUrl(GenericUrl tokenServerUrl)

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

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-api-client/latest/com.google.api.client.googleapis.auth.oauth2.GoogleCredential.Builder` |   |

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

### setTransport(HttpTransport transport)

    public GoogleCredential.Builder setTransport(HttpTransport transport)

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

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-api-client/latest/com.google.api.client.googleapis.auth.oauth2.GoogleCredential.Builder` |   |

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