Google Analytics API请求返回captcha



从昨天开始,我们与Google Analytics API的连接返回一个HTML页面,其中。。。captcha。有人经历过这样的事情吗?

我们将API与PHP库一起使用。我们检索报告的代码(它封装在我们自己的类中,但它使用google/apiclient包(:

// Create analytics
$this->analytics = new Google_Service_AnalyticsReporting($this->client);
// Create the ReportRequest object.
$request = new Google_Service_AnalyticsReporting_ReportRequest();
$request->setViewId($view_id);
$request->setDateRanges($this->dateRanges);
$request->setMetrics( array_values( $this->metrics ) );
$request->setDimensions( array_values( $this->dimensions ) );
$request->setSegments($this->segments);
$body = new Google_Service_AnalyticsReporting_GetReportsRequest();
$body->setReportRequests( array( $request) );
try {
$reports = $this->analytics->reports->batchGet( $body );
}
catch(Google_Service_Exception $e)
{
echo"Error (1)...n";
echo $e->getMessage() . "n";
$this->lastError = json_decode($e->getMessage());
return false;
}

我们发现了一个谷歌服务异常,错误消息如下:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head><meta http-equiv="content-type" content="text/html; charset=utf-8"><meta name="viewport" content="initial-scale=1"><title>https://analyticsreporting.googleapis.com/v4/reports:batchGet</title></head>
<body style="font-family: arial, sans-serif; background-color: #fff; color: #000; padding:20px; font-size:18px;" onload="e=document.getElementById('captcha');if(e){e.focus();}">
<div style="max-width:400px;">
<hr noshade size="1" style="color:#ccc; background-color:#ccc;"><br>
<form id="captcha-form" action="index" method="post">
To continue, please type the characters below:<br><br>
<img src="/sorry/image?id=14645528721876966739&amp;q=EgSIkL9bGIjOzu4FIhkA8aeDSycUmKeaKy3bPExiN-Ol2PpxQzOfMgFj&amp;hl=en&amp;continue=https://analyticsreporting.googleapis.com/v4/reports:batchGet" border="1" alt="Please enable images"><br><br>
<input type="text" name="captcha" value="" id="captcha" size="12" style="font-size:16px; padding:3px 0 3px 5px; margin-left:0px;"><br><br><br>
<input type="submit" name="btn-submit" value="Submit" style="font-size:18px; padding:4px 0;">
<input type='hidden' name='q' value='EgSIkL9bGIjOzu4FIhkA8aeDSycUmKeaKy3bPExiN-Ol2PpxQzOfMgFj'><input type="hidden" name="continue" value="https://analyticsreporting.googleapis.com/v4/reports:batchGet">
</form>
<hr noshade size="1" style="color:#ccc; background-color:#ccc;">
<div style="font-size:13px;">
<b>About this page</b><br><br>
Our systems have detected unusual traffic from your computer network.  This page checks to see if it&#39;s really you sending the requests, and not a robot.  <a href="#" onclick="document.getElementById('infoDiv').style.display='block';">Why did this happen?</a><br><br>
<div id="infoDiv" style="display:none; background-color:#eee; padding:10px; margin:0 0 15px 0; line-height:1.4em;">
This page appears when Google automatically detects requests coming from your computer network which appear to be in violation of the <a href="//www.google.com/policies/terms/">Terms of Service</a>. The block will expire shortly after those requests stop.  In the meantime, solving the above CAPTCHA will let you continue to use our services.<br><br>This traffic may have been sent by malicious software, a browser plug-in, or a script that sends automated requests.  If you share your network connection, ask your administrator for help &mdash; a different computer using the same IP address may be responsible.  <a href="//support.google.com/websearch/answer/86640">Learn more</a><br><br>Sometimes you may be asked to solve the CAPTCHA if you are using advanced terms that robots are known to use, or sending requests very quickly.
</div>
IP address: xxx.xxx.xxx.xxx<br>Time: 2019-11-19T08:25:44Z<br>URL: https://analyticsreporting.googleapis.com/v4/reports:batchGet<br>
</div>
</div>
</body>
</html>

如果有人也经历过这种情况或有解决方案,请告诉我。

提前谢谢。

这可能是谷歌采取了一些安全措施来处理流量的大幅飙升。我还知道,他们在2019年11月4日更新了API的错误消息,这可能就是为什么我们现在收到了这个错误,而不是以前的其他错误。

我从谷歌收到的电子邮件:

"我们将从2019年11月4日开始将谷歌分析API升级为新的技术基础设施堆栈。由于此更改,客户端将在失败的API请求的响应错误消息文本中看到一些差异。">

"如果您的应用程序或日志分析工作流程依赖于Management API v3或Core Reporting API v3响应中提供的特定措辞,则您需要更新代码以反映新的错误响应文本。请注意,由于错误消息的确切措辞随时可能更改,我们强烈建议在处理API响应时对特定消息文本进行硬编码。">

今天我的请求失败了,在我的错误日志中提供了一个captcha图像,生成了404。我收到的错误:

"我们的系统检测到来自您的计算机网络的异常流量。此页面检查是否真的是您发送的请求,而不是机器人。">

"阻止将在这些请求停止后不久过期。同时,解决上述CAPTCHA将使您能够继续使用我们的服务。">

从那以后,我发现该服务在不需要任何代码更改的情况下以小剂量重新运行。

我建议再试一次,并限制请求数量,直到服务100%恢复。

最新更新