public interface

# SearchAuthApi

com.google.android.gms.search.SearchAuthApi

## Class Overview

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();
     }
     }

## Summary

Nested Classes
interface | SearchAuthApi.GoogleNowAuthResult | Result of `getGoogleNowAuth(GoogleApiClient, String)`.

Public Methods
abstract PendingResult<Status> | clearToken(GoogleApiClient client, String accessToken) Clears an access token from the cache.
abstract PendingResult<SearchAuthApi.GoogleNowAuthResult> | getGoogleNowAuth(GoogleApiClient client, String webAppClientId) Obtains authorization for the caller to use the Now API to publish to the Google Now user, if any, on this device.

## Public Methods

#### public abstract PendingResult<Status> clearToken (GoogleApiClient client, String accessToken)

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` that includes `API`.
accessToken | the access token to be cleared from the cache.

##### Returns

- Pending result for `Status`.

#### public abstract PendingResult<SearchAuthApi.GoogleNowAuthResult> getGoogleNowAuth (GoogleApiClient client, String webAppClientId)

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` that includes `API`.
webAppClientId | Client ID, in the Google Developer Console, of the web application that will be using the Now API.

##### Returns

- Pending result for `SearchAuthApi.GoogleNowAuthResult`.