使用 Google 自定义搜索 API 进行日期范围搜索

Amr*_*Amr 6 google-custom-search google-image-search

我正在使用 Google 自定义搜索 API 来搜索图像。我的实现使用 Java,这就是我构建搜索字符串的方式:

URL url = new URL("https://ajax.googleapis.com/ajax/services/search/images?"
                + "v=1.0&q=barack%20obama&userip=INSERT-USER-IP");
Run Code Online (Sandbox Code Playgroud)

我将如何修改 URL 以限制搜索结果,例如:2014-08-152014-09-31

小智 7

您可以使用参数指定日期范围sort。对于您的示例,您可以将其添加到查询字符串中:sort=date:r:20140815:20140931

这记录在https://developers.google.com/custom-search/docs/structed_data#page_dates

另外,如果您使用 Google 的 Java API,您可以使用该类Query及其 setSort()方法,而不是手动构建 URL。