@Beta public class GoogleAccountCredential extends Object implements HttpRequestInitializer
Beta
When fetching a token, any thrown GoogleAuthException
would be wrapped:
GooglePlayServicesAvailabilityException
would be wrapped inside of GooglePlayServicesAvailabilityIOException
UserRecoverableAuthException
would be wrapped inside of UserRecoverableAuthIOException
GoogleAuthException
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. |
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. |
Sleeper |
getSleeper()
Returns the sleeper.
|
String |
getToken()
Returns an OAuth 2.0 access token.
|
void |
initialize(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(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(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(HttpRequest request)
initialize
in interface HttpRequestInitializer
public 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 BackOff getBackOff()
getToken()
or null
for none.public GoogleAccountCredential setBackOff(BackOff backOff)
getToken()
or null
for none.public final Sleeper getSleeper()
public final GoogleAccountCredential setSleeper(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.
IOException
com.google.android.gms.auth.GoogleAuthException
Copyright © 2010–2021 Google. All rights reserved.