在Google自定义搜索API上无法获得超过100个结果 [英] Unable to get results more than 100 results on google custom search api

查看:157
本文介绍了在Google自定义搜索API上无法获得超过100个结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I need to use Google Custom Search API https://developers.google.com/custom-search/v1/overview. From that page, it said:

对于CSE用户,该API每天免费提供100个搜索查询. 如果您需要更多服务,可以在开发人员中注册以进行结算 安慰.额外的请求每1000个查询需支付$ 5,最多1万次 每天的查询次数.

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

I already sign up for billing inside the developer console. However, I still could not retrieve results more than 100. What things should I do more? https://www.googleapis.com/customsearch/v1?cx=CSE_INSTANCE&key=API_KEY&q=QUERY&start=100

{错误:{错误:[{域:全局",原因:无效",消息: 无效值"}],代码:400,消息:无效值"}}

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

推荐答案

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

Query: Definition
https://support.google.com/customsearch/answer/1361951

来自Google Site Search引擎的任何实际用户查询,包括但 不限于使用XML在您的网站上安装的搜索引擎, iFrame或自定义搜索元素.

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个以上的结果.

That means you would probably need to send eleven queries to get more than 100 results.

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)请求.

Check every response and if error code is 400, you can stop - there is probably no need to send next (&start=previous+10) request.

现在,您可以合并响应并开始构建结果页面.

Now you can merge responses and start building results page.

Google自定义搜索和Google站点搜索最多返回10个结果 每个查询.如果您要向用户显示10个以上的结果, 您可以发出多个请求(使用start = 0,start = 11 ... 参数)并在单个页面上显示结果.在这种情况下, Google会将每个请求视为一个单独的查询,如果您 使用Google Site Search,每个查询都将计入您的限制.

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.

上面我已经描述了,也许有更好的方法可以做到这一点. (但是,我不确定批处理API调用.)

There might be a better way to do this then I described above. (But, I'm not sure about batching API calls.)

(最后)可能会回答您的问题:我进行了不止几个测试,但是start大于100的我没有任何运气(我和您一样-<Response [400]>).我正在使用已启用结算功能的项目中的浏览器密钥". 这可能意味着我们无法获得使用CSE API获得101、102、103等结果.

And (finally) possible answer to your question: I made more than few tests, but I haven't had any luck with start greater than 100 (I was getting the same as you - <Response [400]>). I'm using "Browser key" from my billing-enabled project. That could mean we can't get 101st, 102nd, 103rd, etc. results with CSE API.

这篇关于在Google自定义搜索API上无法获得超过100个结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆