google-api - 无法在 Google 自定义搜索 api 上获取超过 100 个结果的结果

标签 google-api search-engine google-custom-search

我需要使用 Google 自定义搜索 API https://developers.google.com/custom-search/v1/overview 。该页面上写道:

For CSE users, the API provides 100 search queries per day for free. If you need more, you may sign up for billing in the Developers Console. Additional requests cost $5 per 1000 queries, up to 10k queries per day.

我已经在开发者控制台内注册了计费。但是,我仍然无法检索到超过 100 条的结果。我还应该做什么? https://www.googleapis.com/customsearch/v1?cx=CSE_INSTANCE&key=API_KEY&q=QUERY&start=100

{ error: { errors: [ { domain: "global", reason: "invalid", message: "Invalid Value" } ], code: 400, message: "Invalid Value" } }

最佳答案

查询:定义
https://support.google.com/customsearch/answer/1361951

Any actual user query from a Google Site Search engine, including but not limited to search engines installed on your website using XML, iFrame, or the Custom Search Element.

这意味着您可能需要发送 11 个查询才能获得超过 100 个结果

GET https://www.googleapis.com/customsearch/v1?&q=QUERY&...&start=1
GET https://www.googleapis.com/customsearch/v1?&q=QUERY&...&start=11
GET https://www.googleapis.com/customsearch/v1?&q=QUERY&...&start=21
GET ...
GET https://www.googleapis.com/customsearch/v1?&q=QUERY&...&start=81
GET https://www.googleapis.com/customsearch/v1?&q=QUERY&...&start=91 
GET https://www.googleapis.com/customsearch/v1?&q=QUERY&...&start=101

检查每个回复,如果 error code400 ,您可以停止 - 可能不需要发送下一个(&start=上一个+10)请求。

现在您可以合并回复并开始构建结果页面。

Google Custom Search and Google Site Search return up to 10 results per query. If you want to display more than 10 results to the user, you can issue multiple requests (using the start=0, start=11 ... parameters) and display the results on a single page. In this case, Google will consider each request as a separate query, and if you are using Google Site Search, each query will count towards your limit.

可能有比我上面描述的更好的方法来做到这一点。 (但是,我不确定 batching API calls 。)

(最后)可能回答你的问题:我做了很多测试,但我对 start 没有任何运气。大于 100(我得到的和你一样 - <Response [400]> )。我正在使用启用计费的项目中的“浏览器 key ”。 That could mean we can't get 101st, 102nd, 103rd, etc.使用 CSE API 的结果。

关于google-api - 无法在 Google 自定义搜索 api 上获取超过 100 个结果的结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35633466/

相关文章:

http-headers - 如果我使用 HTTP 代码 418 AKA "I' m a teapot 响应 robots.txt 的请求”,这会让搜索引擎不喜欢我吗?

javascript - 谷歌自定义搜索——更改 'no results' 消息

search-engine - Google Search API 与专用搜索引擎

php - 使用 google api 客户端 php 刷新 token

php - 使用 PHP 连接到 Google Analytics API

php - 获取状态参数google api登录

javascript - 为什么谷歌网站管理员工具看不到我网站的静态版本,而是动态版本的模板?

python - 尽管添加了正确的范围,但带有 Python 的 Google Drive API 仍不允许文件下载

c# - 如何获取搜索引擎有效 URL 的数据库?

asp.net - 沙盒化 Google 自定义搜索引擎的样式