Google CSE API 返回同一图像的多个变体

Google CSE API returning multiple variations of same image

提问人:Ancient Bison 提问时间:10/7/2023 更新时间:10/7/2023 访问量:27

问:

当向谷歌 CSE API 发送请求时,我最终得到了同一张图片的多个变体。

const pagesToDownload = 1;
let pagesDownloaded = 0;

(async () => {
  const { google } = require('googleapis');
  
  const search = google.customsearch('v1');

  const query = 'pasta';

  let erroring = false;

  const nextPage = () => {
    if (pagesDownloaded != pagesToDownload && !erroring) {
      search.cse.list({
        q: query,
        auth: process.env['CX_KEY'],
        cx: "410a480db45d74a71",
        searchType: 'image',
        start: 1 + (pagesDownloaded * 10),
        fileType: "jpeg,jpg,png,gif,ico,bmp"
      }, async (err, res) => {
        if (err) {
          console.log("REQUEST FAILED: " + err);
          erroring = true;
        } else {
          console.log(res);
          await downloadImagesFromSearchResult(res);
          pagesDownloaded++;
          nextPage();
        }
      });
    } else {
      console.log("Successfully downloaded %d images", pagesDownloaded * 10);
    }
  }
  nextPage();
})();

我试过打开和关闭重复过滤器,但都没有区别。下面是同一请求中返回的三张图片的示例:

图像 1 图像 2 图像 3
Image 1 Image 2 Image 3

我该如何删除重复项?

节点 .js 图像 谷歌 API 谷歌自定义搜索

评论


答: 暂无答案