首页 文章

使用无效的Google adwords帐户显示错误

提问于
浏览
0

我是Google adwords - My client center的新手 . 我有一个网站,可以使用Yii框架查看所有MCC广告系列,广告组,广告等 . 它工作正常 .

我的问题是,如果Mcc电子邮件或密码或客户端ID无效,它会显示如下代码的错误 .

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    */

但我希望将错误显示为“您的帐户无效” . 请建议我可以在哪里写条件来检查帐户是否有效 .

我对此并不太了解 . 我搜索了谷歌adwords api客户端库,发现以下“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”文件 .

在视图文件[mysite / protected / views / site / view.php]中,我将Adwords函数称为,

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

它返回所有广告系列 . 但是如果我提供了错误的配置细节,则会显示上述错误[无法获得authToken . 原因:BadAuthentication] . 我想以指定的格式显示错误 . 请指教 .

1 回答

  • 0

    @lifeline,当您调用方法 $user->GetService (GetCampaings.php)时会发生错误 . 如果您想使用示例代码来获取活动,请在以下行中处理异常:

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

    我建议你阅读AdWords API documentation,因为 GetService 方法会抛出很多不同的异常,具体取决于服务类型(你使用的是 CampaignService ) . 尝试详细了解AdWords API中的错误处理,以减少未来的麻烦 . :)

    此外,用于身份验证的ClientLogin方法(您正在使用的)已被正式弃用 . 查看更多详情here .

相关问题