@Beta public class GoogleAccountCredential extends Object implements com.google.api.client.http.HttpRequestInitializer
Beta
When fetching a token, any thrown GoogleAuthException would be wrapped:
GooglePlayServicesAvailabilityException would be wrapped inside of
GooglePlayServicesAvailabilityIOExceptionUserRecoverableAuthException would be wrapped inside of
UserRecoverableAuthIOExceptionGoogleAuthException when be wrapped inside of GoogleAuthIOException
Upgrade warning: in prior version 1.14 exponential back-off was enabled by default when I/O
exception was thrown inside getToken(), but starting with version 1.15 you need to call
setBackOff(com.google.api.client.util.BackOff) with ExponentialBackOff to enable it.
| Constructor and Description |
|---|
GoogleAccountCredential(android.content.Context context,
String scope) |
| Modifier and Type | Method and Description |
|---|---|
android.accounts.Account[] |
getAllAccounts()
Returns all Google accounts or
null for none. |
com.google.api.client.util.BackOff |
getBackOff()
Returns the back-off policy which is used when an I/O exception is thrown inside
getToken() or null for none. |
android.content.Context |
getContext()
Returns the context.
|
GoogleAccountManager |
getGoogleAccountManager()
Returns the Google account manager.
|
String |
getScope()
Returns the scope to use on
GoogleAuthUtil.getToken(android.content.Context, java.lang.String, java.lang.String). |
android.accounts.Account |
getSelectedAccount()
Returns the selected Google account or
null for none. |
String |
getSelectedAccountName()
Returns the selected Google account name (e-mail address), for example
"johndoe@gmail.com", or null for none. |
com.google.api.client.util.Sleeper |
getSleeper()
Returns the sleeper.
|
String |
getToken()
Returns an OAuth 2.0 access token.
|
void |
initialize(com.google.api.client.http.HttpRequest request) |
android.content.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.
|
GoogleAccountCredential |
setBackOff(com.google.api.client.util.BackOff backOff)
Sets the back-off policy which is used when an I/O exception is thrown inside
getToken()
or null for none. |
GoogleAccountCredential |
setSelectedAccount(android.accounts.Account selectedAccount)
Sets the selected Google
Account or null for none. |
GoogleAccountCredential |
setSelectedAccountName(String accountName)
Sets the selected Google account name (e-mail address) -- for example
"johndoe@gmail.com" -- or null for none. |
GoogleAccountCredential |
setSleeper(com.google.api.client.util.Sleeper sleeper)
Sets the sleeper.
|
static GoogleAccountCredential |
usingAudience(android.content.Context context,
String audience)
Sets the audience scope to use with Google Cloud Endpoints.
|
static GoogleAccountCredential |
usingOAuth2(android.content.Context context,
Collection<String> scopes)
Constructs a new instance using OAuth 2.0 scopes.
|
public GoogleAccountCredential(android.content.Context context,
String scope)
context - contextscope - scope to use on GoogleAuthUtil.getToken(android.content.Context, java.lang.String, java.lang.String)public static GoogleAccountCredential usingOAuth2(android.content.Context context, Collection<String> scopes)
context - contextscopes - non empty OAuth 2.0 scope listpublic static GoogleAccountCredential usingAudience(android.content.Context context, String audience)
context - contextaudience - audiencepublic final GoogleAccountCredential setSelectedAccountName(String accountName)
"johndoe@gmail.com" -- or null for none.public final GoogleAccountCredential setSelectedAccount(android.accounts.Account selectedAccount)
Account or null for none.
Caller must ensure the given Google account exists.
public void initialize(com.google.api.client.http.HttpRequest request)
initialize in interface com.google.api.client.http.HttpRequestInitializerpublic final android.content.Context getContext()
public final String getScope()
GoogleAuthUtil.getToken(android.content.Context, java.lang.String, java.lang.String).public final GoogleAccountManager getGoogleAccountManager()
public final android.accounts.Account[] getAllAccounts()
null for none.public final android.accounts.Account getSelectedAccount()
null for none.public com.google.api.client.util.BackOff getBackOff()
getToken() or null for none.public GoogleAccountCredential setBackOff(com.google.api.client.util.BackOff backOff)
getToken()
or null for none.public final com.google.api.client.util.Sleeper getSleeper()
public final GoogleAccountCredential setSleeper(com.google.api.client.util.Sleeper sleeper)
Sleeper.DEFAULT.public final String getSelectedAccountName()
"johndoe@gmail.com", or null for none.public final android.content.Intent newChooseAccountIntent()
Must be run from the main UI thread.
public String getToken() throws IOException, com.google.android.gms.auth.GoogleAuthException
Must be run from a background thread, not the main UI thread.
IOExceptioncom.google.android.gms.auth.GoogleAuthExceptionCopyright © 2010–2018 Google. All rights reserved.