public class GoogleAccountCredential extends Object implements HttpRequestInitializer
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| 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. |
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. |
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 |
setSelectedAccountName(String accountName)
Sets the selected Google account name (e-mail address) -- for example
"johndoe@gmail.com" -- or null for none. |
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,
String scope,
String... extraScopes)
Constructor 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, String scope, String... extraScopes)
context - contextscope - first OAuth 2.0 scopeextraScopes - any additional OAuth 2.0 scopespublic 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 void initialize(HttpRequest request)
initialize in interface 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 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 final 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-2012 Google. All Rights Reserved.