com.google.android.gms.search.SearchAuthApi |
API for Google Search auth.
Usage example:
{@code SearchAuthApi searchAuthApi = SearchAuth.SearchAuthApi; GoogleApiClient client = new GoogleApiClient.Builder(context) .addApi(SearchAuth.API) .build(); client.connect(); try { // Invoke methods of searchAuthApi. } finally { client.disconnect(); } }
Nested Classes | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
SearchAuthApi.GoogleNowAuthResult | Result of getGoogleNowAuth(GoogleApiClient, String) . |
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Clears an access token from the cache.
| |||||||||||
Obtains authorization for the caller to use the Now API to publish to the Google Now user, if
any, on this device.
|
Clears an access token from the cache. Use this to remove revoked access tokens from the cache
before calling getGoogleNowAuth(GoogleApiClient, String)
to obtain new authorization.
Parameters | |
---|---|
client |
GoogleApiClient :
GoogleApiClient that includes API . |
accessToken |
String :
the access token to be cleared from the cache. |
Returns | |
---|---|
PendingResult<Status> |
Pending result for Status .
|
Obtains authorization for the caller to use the Now API to publish to the Google Now user, if any, on this device.
Access tokens returned by this method are cached. If the token is revoked later, on the
server, either by the developer or the user, this method will continue returning that access
token from the cache until the cache entry expires. Using a revoked access token in Google Now
APIs will result in an error like "invalid_token", "Token expired or revoked", "Invalid
Credentials", etc. In such cases the revoked access token must be removed from the cache using
clearToken(GoogleApiClient, String)
before this method is called to obtain new
authorization.
Usage example:
{@code SearchAuthApi.GoogleNowAuthResult authResult; try { authResult = searchAuthApi.getGoogleNowAuth(client, WEB_APP_CLIENT_ID) .await(); } finally { client.disconnect(); } Status status = authResult.getStatus(); if (status.isSuccess()) { GoogleNowAuthState authState = authResult.getGoogleNowAuthState(); if (authState.getAuthCode() != null) { // Send auth code to your server and from your server obtain OAuth refresh // and access tokens. } else if (authState.getAccessToken() != null) { // Already obtained auth code before. To get a new auth code revoke this // token and retry. } } }
Parameters | |
---|---|
client |
GoogleApiClient :
GoogleApiClient that includes API . |
webAppClientId |
String :
Client ID, in the Google Developer Console, of the web application
that will be using the Now API. |
Returns | |
---|---|
PendingResult<SearchAuthApi.GoogleNowAuthResult> |
Pending result for SearchAuthApi.GoogleNowAuthResult .
|