我和一个 friend 正在尝试在处理中创建一个照片马赛克生成器。我们希望能够使用自定义搜索 API 从 Google 提取 100 张图像,限制图像大小和主色以及其他一些东西。我们想要保存这些图像,以便我们可以在程序中处理它们。我们还希望使用来自 GUI 的数据来构建 API 调用,即搜索关键字。
以下代码片段显示了我们想要限制图像搜索的参数:
var searcher = new google.search.customSearchControl.getImageSearcher();
searcher.setRestriction(
google.search.Search.RESTRICT_SAFESEARCH,
google.search.Search.SAFESEARCH_STRICT
);
searcher.setRestriction(
google.search.customSearchControl.getImageSearcher.RESTRICT_IMAGESIZE,
google.search.customSearchControl.getImageSearcher.IMAGESIZE_MEDUIM
);
searcher.setRestriction(
google.search.customSearchControl.getImageSearcher.RESTRICT_COLORFILTER,
google.search.customSearchControl.getImageSearcher.COLOR_RED
);
searcher.execute(keyword);
我们只是不确定如何限制搜索结果的数量或返回数据的格式。是 JSON 吗?
最佳答案
这是如果您正在构建 URL,而不是以编程方式执行的情况。
- 要将
JSON
指定为返回值,请将&alt=json
附加到请求网址的末尾。 - 要限制返回的搜索数量,请使用
num=50
作为参数之一
来源:https://developers.google.com/custom-search/v1/using_rest#query-params
关于javascript - 如何使用 Google 自定义搜索 API 下载 100 张图像以用于处理?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16025688/