【问题标题】:Google page speed insights API requiring captcha when using google API credentials使用谷歌 API 凭证时需要验证码的谷歌页面速度洞察 API
【发布时间】:2019-12-08 06:34:29
【问题描述】:

我正在尝试使用 PHP 和 curl 访问此处记录的 PageSpeed Insights API https://developers.google.com/speed/docs/insights/v5/about,并得到如下响应:

{
   'captchaResult' => "CAPTCHA_NEEDED"
}

我查询 API 的代码如下所示:

$url = 'https://google.com';
$cmd = "curl -H 'Cache-Control: no-cache' https://www.googleapis.com/pagespeedonline/v5/runPagespeed?url=$url&key={MY_KEY}";
$result = json_decode(`$cmd`, true);

文档指出“如果您计划以自动化方式使用 API 并每秒进行多次查询,您将需要一个 API 密钥”。我已经在开发者控制台中创建了一个 API 密钥,但仍然得到上述结果。

理想情况下,我希望能够每秒发出 10-20 个请求的短脉冲。

我有两个问题:

  1. 是否有任何文档可用于 PageSpeed Insights API 中的速率限制?

  2. 如何满足此 API 的 CAPTCHA_NEEDED 要求?

【问题讨论】:

    标签: php curl google-api pagespeed-insights


    【解决方案1】:

    您需要通过credentials page 获取 API 密钥才能在没有验证码的情况下继续操作。

    然后用上一步得到的key设置环境变量,例如:

    MY_KEY=adasda5434sdsa234sasdd

    设置网址:

    URL="https://EXAMPLE.com"

    然后您可以使用 CLI 中的服务:

    curl https://www.googleapis.com/pagespeedonline/v5/runPagespeed?url={$URL}&&key={$MY_KEY}

    此外,您可以使用不带变量的 curl:

    curl https://www.googleapis.com/pagespeedonline/v5/runPagespeed?url=https://EXAMPLE.com&&key=adasda5434sdsa234sasdd

    文档available

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-06-07
      • 1970-01-01
      • 1970-01-01
      • 2014-11-18
      • 2017-09-23
      • 2013-07-01
      • 2021-10-02
      • 1970-01-01
      相关资源
      最近更新 更多