谷歌自定义搜索API使用start=100会导致400错误。

13

我有一个脚本,使用谷歌自定义搜索API,遍历多个结果页面。

https://www.googleapis.com/customsearch/v1?key=[[KEY]]&num=10&hl=en&start=0&cx=[[CX]]&q=%22bank%22&sort=date&googlehost=www.google.com

https://www.googleapis.com/customsearch/v1?key=[[KEY]]&num=10&hl=en&start=10&cx=[[CX]]&q=%22bank%22&sort=date&googlehost=www.google.com

https://www.googleapis.com/customsearch/v1?key=[[KEY]]&num=10&hl=en&start=20&cx=[[CX]]&q=%22bank%22&sort=date&googlehost=www.google.com
在上述所有示例中,我都获得了适当的响应。查询响应声称有17,900个搜索结果。然而,当脚本达到start=100时:
https://www.googleapis.com/customsearch/v1?key=[[KEY]]&num=10&hl=en&start=100&cx=[[CX]]&q=%22bank%22&sort=date&googlehost=www.google.com

我收到了以下响应(这是JSON响应转换为PHP对象的结果):

stdClass Object (
        [error] => stdClass Object
            (
                [errors] => Array
                    (
                        [0] => stdClass Object
                            (
                                [domain] => global
                                [reason] => invalid
                                [message] => Invalid Value
                            )
                    )
                [code] => 400
                [message] => Invalid Value
            ) )
尽管我在start=90收到的结果声称下一页存在,但事实并非如此。
"nextPage": [
   {
    "title": "Google Custom Search - \"bank\"",
    "totalResults": "17900",
    "searchTerms": "\"bank\"",
    "count": 10,
    "startIndex": 100,
    "inputEncoding": "utf8",
    "outputEncoding": "utf8",
    "safe": "off",
    "cx": "[[CX VALUE]]",
    "sort": "date",
    "googleHost": "www.google.com",
    "hl": "en"
   }
  ]
使用API进行测试发现,当start=92时会出现无效值错误。此外,每次关键字搜索都会在该页面上出现此错误。如能提供帮助解决问题将不胜感激。这是因为这是Google自定义搜索的免费版本吗?
1个回答

18

这些信息并不容易找到,我只在Google.com唯一的一个官方页面中发现了一个单行描述nextPage响应元素的条目,位于Custom Search JSON API文档中:

注意:此API仅返回前100个结果。

没有提到这仅适用于免费API。我还找到了用户报告,证实即使您注册计费,该限制也适用,例如请参见此相关问题链接的博客文章

另一方面,在每日100个查询限制(而非您看到的结果限制)有很好的记录,并且有关如何绕过该限制的信息无处不在(当然是通过注册计费来实现)。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接