GoogleApiClientUtil

public class GoogleApiClientUtil
extends Object

java.lang.Object
   ↳ com.android.tradefed.util.GoogleApiClientUtil


Utils for create Google API client.

Summary

Fields

public static final String APP_NAME

Public constructors

GoogleApiClientUtil()

Public methods

static HttpRequestInitializer configureRetryStrategy(HttpRequestInitializer initializer)

Setup a retry strategy for the provided HttpRequestInitializer.

static GoogleCredential createCredential( scopes, File primaryKeyFile, String hostOptionKeyFileName, File... backupKeyFiles)

Try to create credential with different key files or from local host.

static GoogleCredential createCredentialFromJsonKeyFile(File file, scopes)

Create credential from json key file.

static GoogleCredential createCredentialFromP12File(String serviceAccount, File keyFile, scopes)

This method is deprecated. It's better to use json key file, since p12 is deprecated by Google App Engine. And json key file have more information.

static HttpRequestInitializer setHttpTimeout(HttpRequestInitializer requestInitializer, int connectTimeout, int readTimeout)

Fields

APP_NAME

public static final String APP_NAME

Public constructors

GoogleApiClientUtil

public GoogleApiClientUtil ()

Public methods

configureRetryStrategy

public static HttpRequestInitializer configureRetryStrategy (HttpRequestInitializer initializer)

Setup a retry strategy for the provided HttpRequestInitializer. In case of server errors requests will be automatically retried with an exponential backoff.

Parameters
initializer HttpRequestInitializer: - an initializer which will setup a retry strategy.

Returns
HttpRequestInitializer an initializer that will retry failed requests automatically.

createCredential

public static GoogleCredential createCredential ( scopes, 
                File primaryKeyFile, 
                String hostOptionKeyFileName, 
                File... backupKeyFiles)

Try to create credential with different key files or from local host.

1. If primaryKeyFile is set, try to use it to create credential. 2. Try to get corresponding key files from HostOptions. 3. Try to use backup key files. 4. Use local default credential.

Parameters
scopes : scopes for the credential.

primaryKeyFile File: the primary json key file; it can be null.

hostOptionKeyFileName String: HostOptions'service-account-json-key-file option's key; it can be null.

backupKeyFiles File: backup key files.

Returns
GoogleCredential a GoogleCredential

Throws
IOException

createCredentialFromJsonKeyFile

public static GoogleCredential createCredentialFromJsonKeyFile (File file, 
                 scopes)

Create credential from json key file.

Parameters
file File: is the p12 key file

scopes : is the API's scope.

Returns
GoogleCredential a GoogleCredential.

Throws
FileNotFoundException
IOException

createCredentialFromP12File

public static GoogleCredential createCredentialFromP12File (String serviceAccount, 
                File keyFile, 
                 scopes)

This method is deprecated.
It's better to use json key file, since p12 is deprecated by Google App Engine. And json key file have more information.

Create credential from p12 file for service account.

Parameters
serviceAccount String: is the service account

keyFile File: is the p12 key file

scopes : is the API's scope.

Returns
GoogleCredential a GoogleCredential.

Throws
GeneralSecurityException

setHttpTimeout

public static HttpRequestInitializer setHttpTimeout (HttpRequestInitializer requestInitializer, 
                int connectTimeout, 
                int readTimeout)

Parameters
requestInitializer HttpRequestInitializer: a HttpRequestInitializer, normally it's GoogleCredential.

connectTimeout int: connect timeout in milliseconds.

readTimeout int: read timeout in milliseconds.

Returns
HttpRequestInitializer a HttpRequestInitializer with timeout.