com.google.api.ads.common.lib.auth
Class ClientLoginTokens

java.lang.Object
  extended by com.google.api.ads.common.lib.auth.ClientLoginTokens

public class ClientLoginTokens
extends Object

ClientLogin token provider.

Example usage:


 ClientLoginTokens clientLoginTokens = new ClientLoginTokens.Builder()
     .forApi(ClientLoginTokens.Api.ADWORDS)
     .fromFile()
     .build();
 String clientLoginToken = clientLoginTokens.requestToken();
If you receive a CAPTCHA challenge you can supply the login token and captcha in the requestToken function like:

 String clientLoginToken;
 try {
   clientLoginToken = clientLoginTokens.requestToken();
 } catch(ClientLoginException e) {
   if (e.getCaptchaInfo != null) {
      String loginCaptcha =
          // redirect user to e.getCaptchaInfo.getCaptchaUrl() to get CAPTCHA;
      String loginToken = captchaInformation.getCaptchaToken();
      clientLoginToken =
          clientLoginTokens.requestToken(loginCaptcha, loginToken);
   }
 }

Author:
Adam Rogal

Nested Class Summary
static class ClientLoginTokens.Api
          Enum representing the API that ClientLoginTokens can be used for.
static class ClientLoginTokens.Builder
          Pre-builder for ClientLoginTokens.
static class ClientLoginTokens.ForApiBuilder
          Builder for ClientLoginTokens.
 
Field Summary
static String ADWORDS_SERVICE
          Deprecated. Use ClientLoginTokens.Api.ADWORDS in Builder#forApi(Api).
static String DFP_SERVICE
          Deprecated. Use ClientLoginTokens.Api.DFP in Builder#forApi(Api).
 
Constructor Summary
ClientLoginTokens(String service)
          Deprecated. Use new ClientLoginTokens.Builder() instead
 
Method Summary
 String from(org.apache.commons.configuration.Configuration config)
          Deprecated. Use new ClientTokens.Builder().forApi(Api.ADWORDS) .from(config) instead.
 String from(String email, String password)
          Deprecated. Use new ClientTokens.Builder().forApi(Api.ADWORDS) .withEmailAndPassword(email, password) instead.
 String from(String email, String password, String loginToken, String loginCaptcha)
          Deprecated. Use new ClientTokens.Builder() .forApi(Api.ADWORDS) .withEmailAndPassword(email, password) .withLoginTokenAndCaptcha(loginToken, loginCaptcha) instead.
 String fromFile()
          Deprecated. Use new ClientTokens.Builder().forApi(Api.ADWORDS) .fromFile() instead.
 String fromFile(File path)
          Deprecated. Use new ClientTokens.Builder().forApi(Api.ADWORDS) .fromFile(path) instead.
 String fromFile(String path)
          Deprecated. Use new ClientTokens.Builder().forApi(Api.ADWORDS) .fromFile(path) instead.
 String fromFile(URL path)
          Deprecated. Use new ClientTokens.Builder().forApi(Api.ADWORDS) .fromFile(path) instead.
 String requestToken()
          Requests a token with the email and password.
 String requestToken(String captchaToken, String captchaAnswer)
          Requests a token with the email and password, along with information used to validate a CAPTCHA'ed account.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ADWORDS_SERVICE

@Deprecated
public static final String ADWORDS_SERVICE
Deprecated. Use ClientLoginTokens.Api.ADWORDS in Builder#forApi(Api).
Service to use to request ClientLogin tokens for AdWords.

See Also:
Constant Field Values

DFP_SERVICE

@Deprecated
public static final String DFP_SERVICE
Deprecated. Use ClientLoginTokens.Api.DFP in Builder#forApi(Api).
Service to use to request ClientLogin tokens for DFP.

See Also:
Constant Field Values
Constructor Detail

ClientLoginTokens

@Deprecated
public ClientLoginTokens(String service)
Deprecated. Use new ClientLoginTokens.Builder() instead

Constructor.

Parameters:
service - the service name i.e. gam or adwords
Method Detail

fromFile

@Deprecated
public String fromFile()
                throws ClientLoginException
Deprecated. Use new ClientTokens.Builder().forApi(Api.ADWORDS) .fromFile() instead.

Loads credentials from a properties file in one of the following locations according to the following order: in the current directory, in the user home directory, in the classpath

Throws:
ClientLoginException

fromFile

@Deprecated
public String fromFile(String path)
                throws ClientLoginException
Deprecated. Use new ClientTokens.Builder().forApi(Api.ADWORDS) .fromFile(path) instead.

Populates this builder from a properties file from a specified path. If not absolute, will look in user home directory, the current classpath and the system classpath.

Parameters:
path - the path to try first as a resource, then as a file
Returns:
Builder populated with properties.
Throws:
ClientLoginException

fromFile

@Deprecated
public String fromFile(File path)
                throws ClientLoginException
Deprecated. Use new ClientTokens.Builder().forApi(Api.ADWORDS) .fromFile(path) instead.

Populates this builder from a properties file from a specified path.

Parameters:
path - the path to load properties from
Returns:
Builder populated with properties.
Throws:
ClientLoginException

fromFile

@Deprecated
public String fromFile(URL path)
                throws ClientLoginException
Deprecated. Use new ClientTokens.Builder().forApi(Api.ADWORDS) .fromFile(path) instead.

Populates this builder from a properties file from a specified path. If not absolute, will look in user home directory, the current classpath and the system classpath.

Parameters:
path - the path to try first as a resource, then as a file
Returns:
Builder populated with properties.
Throws:
ClientLoginException

from

@Deprecated
public String from(org.apache.commons.configuration.Configuration config)
            throws ClientLoginException
Deprecated. Use new ClientTokens.Builder().forApi(Api.ADWORDS) .from(config) instead.

Obtains a ClientLoginToken either stored in the specified configuration or using an email and password stored in the configuration to obtain a new one

Understands the following properties suffixes: For example, the AdWords ClientLoginToken can be read from: api.adwords.clientLoginToken

Parameters:
config -
Returns:
ClientLoginToken on success or an exception.
Throws:
ClientLoginException

from

@Deprecated
public String from(String email,
                              String password)
            throws ClientLoginException
Deprecated. Use new ClientTokens.Builder().forApi(Api.ADWORDS) .withEmailAndPassword(email, password) instead.

Requests the user's authentication token.

Parameters:
email - the email to fetch the token for
password - the password to fetch the token for
Returns:
the user's new authentication token
Throws:
ClientLoginException - if the token could not be generated

from

@Deprecated
public String from(String email,
                              String password,
                              String loginToken,
                              String loginCaptcha)
            throws ClientLoginException
Deprecated. Use new ClientTokens.Builder() .forApi(Api.ADWORDS) .withEmailAndPassword(email, password) .withLoginTokenAndCaptcha(loginToken, loginCaptcha) instead.

Requests the user's authentication token.

Parameters:
email - the email to fetch the token for
password - the password to fetch the token for
loginToken - the login token. Can be null if not needed.
loginCaptcha - the login CAPTCHA. Can be null if not needed.
Returns:
the user's new authentication token
Throws:
ClientLoginException - if the token could not be generated

requestToken

public String requestToken(String captchaToken,
                           String captchaAnswer)
                    throws com.google.api.client.googleapis.auth.clientlogin.ClientLoginResponseException,
                           IOException
Requests a token with the email and password, along with information used to validate a CAPTCHA'ed account.

Parameters:
captchaToken - the CAPTCHA token. i.e. .ClientLogin.ErrorInfo#captchaToken ErrorInfo#captchaToken
captchaAnswer - the CAPTCHA answer. i.e. fetched from .ClientLogin.ErrorInfo#captchaUrl ErrorInfo#captchaUrl
Returns:
the client login token
Throws:
com.google.api.client.googleapis.auth.clientlogin.ClientLoginResponseException - if the token could not be retrieved
IOException - if there was a problem making the request

requestToken

public String requestToken()
                    throws com.google.api.client.googleapis.auth.clientlogin.ClientLoginResponseException,
                           IOException
Requests a token with the email and password.

Returns:
the client login token
Throws:
com.google.api.client.googleapis.auth.clientlogin.ClientLoginResponseException - if the token could not be retrieved, possibly due to a CAPTCHA challenge
IOException - if there was a problem making the request


Copyright © 2012. All Rights Reserved.