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 class GoogleAccountCredential implements HttpRequestInitializer

Beta   

Manages authorization and account selection for Google accounts.

When fetching a token, any thrown GoogleAuthException would be wrapped:

- GooglePlayServicesAvailabilityException would be wrapped inside of [GooglePlayServicesAvailabilityIOException](https://docs.cloud.google.com/java/docs/reference/google-api-client/latest/com.google.api.client.googleapis.extensions.android.gms.auth.GooglePlayServicesAvailabilityIOException)
- UserRecoverableAuthException would be wrapped inside of [UserRecoverableAuthIOException](https://docs.cloud.google.com/java/docs/reference/google-api-client/latest/com.google.api.client.googleapis.extensions.android.gms.auth.UserRecoverableAuthIOException)
- GoogleAuthException when be wrapped inside of [GoogleAuthIOException](https://docs.cloud.google.com/java/docs/reference/google-api-client/latest/com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAuthIOException)

Upgrade warning: in prior version 1.14 exponential back-off was enabled by default when I/O
exception was thrown inside [#getToken](https://docs.cloud.google.com/java/docs/reference/google-api-client/latest/com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential#com_google_api_client_googleapis_extensions_android_gms_auth_GoogleAccountCredential_getToken_), but starting with version 1.15 you need to call
[#setBackOff](https://docs.cloud.google.com/java/docs/reference/google-api-client/latest/com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential#com_google_api_client_googleapis_extensions_android_gms_auth_GoogleAccountCredential_setBackOff_) with ExponentialBackOff to enable it.

## Inheritance

[java.lang.Object](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html) \> GoogleAccountCredential

## Implements

com.google.api.client.http.HttpRequestInitializer

## Inherited Members

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

## Static Methods

### usingAudience(Context context, String audience)

    public static GoogleAccountCredential usingAudience(Context context, String audience)

Sets the audience scope to use with Google Cloud Endpoints.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `context` | `android.content.Context` context |
| `audience` | `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` audience |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-api-client/latest/com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential` | new instance |

### usingOAuth2(Context context, Collection\<String\> scopes)

    public static GoogleAccountCredential usingOAuth2(Context context, Collection<String> scopes)

Constructs a new instance using OAuth 2.0 scopes.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `context` | `android.content.Context` context |
| `scopes` | `https://docs.oracle.com/javase/8/docs/api/java/util/Collection.html<https://docs.oracle.com/javase/8/docs/api/java/lang/String.html>` non empty OAuth 2.0 scope list |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-api-client/latest/com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential` | new instance |

## Constructors

### GoogleAccountCredential(Context context, String scope)

    public GoogleAccountCredential(Context context, String scope)

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `context` | `android.content.Context` context |
| `scope` | `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` scope to use on GoogleAuthUtil#getToken |

## Methods

### getAllAccounts()

    public final Account[] getAllAccounts()

Returns all Google accounts or `null` for none.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `android.accounts.Account[]` |   |

### getBackOff()

    public BackOff getBackOff()

Returns the back-off policy which is used when an I/O exception is thrown inside [#getToken](https://docs.cloud.google.com/java/docs/reference/google-api-client/latest/com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential#com_google_api_client_googleapis_extensions_android_gms_auth_GoogleAccountCredential_getToken_) or `null` for none.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `com.google.api.client.util.BackOff` |   |

### getContext()

    public final Context getContext()

Returns the context.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `android.content.Context` |   |

### getGoogleAccountManager()

    public final GoogleAccountManager getGoogleAccountManager()

Returns the Google account manager.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-api-client/latest/com.google.api.client.googleapis.extensions.android.accounts.GoogleAccountManager` |   |

### getScope()

    public final String getScope()

Returns the scope to use on GoogleAuthUtil#getToken.

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

### getSelectedAccount()

    public final Account getSelectedAccount()

Returns the selected Google account or `null` for none.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `android.accounts.Account` |   |

### getSelectedAccountName()

    public final String getSelectedAccountName()

Returns the selected Google account name (e-mail address), for example `
"johndoe@gmail.com"`, or `null` for none.

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

### getSleeper()

    public final Sleeper getSleeper()

Returns the sleeper.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `com.google.api.client.util.Sleeper` |   |

### getToken()

    public String getToken()

Returns an OAuth 2.0 access token.

Must be run from a background thread, not the main UI thread.

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

| **Exceptions** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/io/IOException.html` |   |
| `com.google.android.gms.auth.GoogleAuthException` |   |

### initialize(HttpRequest request)

    public void initialize(HttpRequest request)

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `request` | `com.google.api.client.http.HttpRequest` |

### newChooseAccountIntent()

    public final Intent newChooseAccountIntent()

Returns an intent to show the user to select a Google account, or create a new one if there are
none on the device yet.

Must be run from the main UI thread.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `android.content.Intent` |   |

### setBackOff(BackOff backOff)

    public GoogleAccountCredential setBackOff(BackOff backOff)

Sets the back-off policy which is used when an I/O exception is thrown inside [#getToken](https://docs.cloud.google.com/java/docs/reference/google-api-client/latest/com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential#com_google_api_client_googleapis_extensions_android_gms_auth_GoogleAccountCredential_getToken_)
or `null` for none.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `backOff` | `com.google.api.client.util.BackOff` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-api-client/latest/com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential` |   |

### setSelectedAccount(Account selectedAccount)

    public final GoogleAccountCredential setSelectedAccount(Account selectedAccount)

Sets the selected Google Account or `null` for none.

Caller must ensure the given Google account exists.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `selectedAccount` | `android.accounts.Account` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-api-client/latest/com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential` |   |

### setSelectedAccountName(String accountName)

    public final GoogleAccountCredential setSelectedAccountName(String accountName)

Sets the selected Google account name (e-mail address) -- for example `
"johndoe@gmail.com"` -- or `null` for none.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `accountName` | `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.extensions.android.gms.auth.GoogleAccountCredential` |   |

### setSleeper(Sleeper sleeper)

    public final GoogleAccountCredential setSleeper(Sleeper sleeper)

Sets the sleeper. The default value is [Sleeper#DEFAULT](https://docs.cloud.google.com/java/docs/reference/google-http-client/latest/com.google.api.client.util.Sleeper.html#com_google_api_client_util_Sleeper_DEFAULT).

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `sleeper` | `com.google.api.client.util.Sleeper` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-api-client/latest/com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential` |   |