gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 17:46:40 25 4
gpt4 key购买 nike

我需要使用 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com