2013-02-21 48 views
0

Im新到Google adwords - My client center。我有一个网站,用Yii框架查看所有MCC广告系列,广告组,广告等。它工作正常。无效谷歌AdWords帐户显示错误

我的问题是,如果麦克电子邮件或密码或客户端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 */ 

但我想显示错误为“您的帐户无效”。请通知我在哪里写条件来检查帐户是否有效。

我对此没有太多的想法。我搜索了google adwords api客户端库,发现以下“http://code.google.com/p/google-api-adwords-php/downloads/list”。之后,下载了aw_api_php_lib_3.2.2.tar.gz并将该代码放置在“mysite/protected /”文件夹中。我修改了“mysite/protected/adwords/src/Google/Api/Ads/AdWords/auth.ini”文件中的配置。

在意见文件[mysite的/保护/视图/网站/ 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]。我想以指定的格式显示错误。请指教。

+0

我脏的修复将是赶上AuthTokenException exceptoins和显示他们很好..这是一个插件或您的代码引发错误? – DarkMukke 2013-02-21 12:44:05

+0

,我必须猜测它是哪个插件吗? – DarkMukke 2013-02-21 15:01:41

+0

@DarkMukke请参阅上面的更多信息。我不知道是哪个抛出错误,可能是Google adwords应用程序出错。如果我错了,请纠正我。谢谢 – lifeline 2013-02-22 04:36:12

回答

0

@lifeline,当您调用方法$user->GetService(GetCampaings.php)时会出现错误。 如果要使用示例代码,以获得campaings,处理以下行除外:

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

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

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