Google自定义搜索API启动= 100导致错误400



我有一个使用Google自定义搜索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自定义搜索的免费版本吗?

此信息根本不容易找到,我发现它仅在Google.com上的一个地方正式提到。我在自定义搜索JSON API文档中找到了一行,描述了nextPage响应元素:

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

没有提及仅限于免费API。我还发现用户报告确认了限制即使您注册账单也适用,例如,请参阅此相关的问题和链接的博客文章。

otoh 100 Queries /day限制(与您看到的结果限制相反)已充分记录,并且有有关如何在任何地方绕过的信息(当然,通过注册计费)。

最新更新