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 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.md.txt)
- 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.md.txt)
- 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.md.txt)

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.md.txt#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.md.txt#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)

```java
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` | `String` audience |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `GoogleAccountCredential` | new instance |

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

```java
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` | `Collection<String>` non empty OAuth 2.0 scope list |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `GoogleAccountCredential` | new instance |

## Constructors

### GoogleAccountCredential(Context context, String scope)

```java
public GoogleAccountCredential(Context context, String scope)
```

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `context` | `android.content.Context` context |
| `scope` | `String` scope to use on GoogleAuthUtil#getToken |

## Methods

### getAllAccounts()

```java
public final Account[] getAllAccounts()
```
Returns all Google accounts or `null` for none.

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

### getBackOff()

```java
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.md.txt#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()

```java
public final Context getContext()
```
Returns the context.

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

### getGoogleAccountManager()

```java
public final GoogleAccountManager getGoogleAccountManager()
```
Returns the Google account manager.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `GoogleAccountManager` |   |

### getScope()

```java
public final String getScope()
```
Returns the scope to use on GoogleAuthUtil#getToken.

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

### getSelectedAccount()

```java
public final Account getSelectedAccount()
```
Returns the selected Google account or `null` for none.

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

### getSelectedAccountName()

```java
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** |
| `String` |   |

### getSleeper()

```java
public final Sleeper getSleeper()
```
Returns the sleeper.

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

### getToken()

```java
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** |
| `String` |   |

| **Exceptions** ||
|---|---|
| **Type** | **Description** |
| `IOException` |   |
| `com.google.android.gms.auth.GoogleAuthException` |   |

### initialize(HttpRequest request)

```java
public void initialize(HttpRequest request)
```

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

### newChooseAccountIntent()

```java
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)

```java
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.md.txt#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** |
| `GoogleAccountCredential` |   |

### setSelectedAccount(Account selectedAccount)

```java
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** |
| `GoogleAccountCredential` |   |

### setSelectedAccountName(String accountName)

```java
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` | `String` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `GoogleAccountCredential` |   |

### setSleeper(Sleeper sleeper)

```java
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.md.txt#com_google_api_client_util_Sleeper_DEFAULT).

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

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `GoogleAccountCredential` |   |