0
votes

Im new to Google adwords - My client center. I have a website to view all the MCC Campaigns, Adgroups, ads etc with Yii framework. It is working fine.

My problem is, if the Mcc Email or Password or Client Id is invalid, it show the error like the below code.

Failed to get authToken. Reason: BadAuthentication 

$response = $this->Login();
095     $fields = $this->ParseResponse($response);
096     if (array_key_exists('Error', $fields)) {
097       $error = $fields['Error'];
098       if (array_key_exists('Info', $fields)) {
099         $error .= ': ' . $fields['Info'];
100       }
101       $url = array_key_exists('Url', $fields) ? $fields['Url'] : NULL;
102       $captchaToken = array_key_exists('CaptchaToken', $fields) ?
103           $fields['CaptchaToken'] : NULL;
104       $captchaUrl = array_key_exists('CaptchaUrl', $fields) ?
105           $fields['CaptchaUrl'] : NULL;
106       throw new AuthTokenException($error, $url, $captchaToken, $captchaUrl);
107     } else if (!array_key_exists('Auth', $fields)) {
108       throw new AuthTokenException('Unknown');
109     } else {
110       return $fields['Auth'];
111     }
112   }
113 
114   /**
115    * Makes the client login request and stores the result.
116    * @return string the response from the ClientLogin API
117    * @throws AuthTokenException if an error occurs during authentication
118    */

But i want display the error as "Your Account is invalid". Please advice where i can write the condition to check the account is valid.

Im not having much idea about this. I searched for the google adwords api client library and found the following "http://code.google.com/p/google-api-adwords-php/downloads/list". After that, downloaded the aw_api_php_lib_3.2.2.tar.gz and placed that code in "mysite/protected/" folder. And i have modified configuration in "mysite/protected/adwords/src/Google/Api/Ads/AdWords/auth.ini" file.

In views file [mysite/protected/views/site/view.php], i have called the Adwords function as,

Yii::import('application.adwords.*');
require_once('examples/v201206/BasicOperations/GetCampaigns.php')
$user = new AdWordsUser();
$user->LogAll();
$result_camp = GetCampaignsExample($user);

It returns all campaigns. But if i provided the wrong configuration details, it shows the above error [Failed to get authToken. Reason: BadAuthentication]. I want to display the error in specified format. Please advice.

1
my dirty fix would be to catch the AuthTokenException exceptoins and display them nice.. Is this a plugin or your code that throws the error ? - DarkMukke
and do i have to guess which plugin it is ? - DarkMukke
@DarkMukke Please see above for more info. Im not sure which throws the error, probably the Google adwords application is through the error. Please correct me if im wrong. Thanks - lifeline

1 Answers

0
votes

@lifeline, the error occurs when you call the method $user->GetService (GetCampaings.php). If you want to use the sample code to get the campaings, handle the exception in the following line:

try{
    $result_camp = GetCampaignsExample($user);
}
catch(Exception $e) {
    // display your error message
}

I recommend you read the AdWords API documentation, because the GetService method can throw a lot of different exceptions, depending on the type of service (you're using the CampaignService). Try to learn more about the error handling in AdWords API, to reduce the future headaches. :)

Furthermore, the ClientLogin method for authentication (that you're using), has been officially deprecated. See more details here.