Search code examples
javascriptimage-processingprocessinggoogle-search-api

How do I download 100 images using Google Custom Search API for use with Processing?


A friend and I are trying to create a Photomosaic generator in Processing. We want to be able to pull 100 images from Google using the Custom Search API, restricting the image size and dominant color, along with few other things. We want to save these images so that we can process them in our program. We also want to use data that will come from the GUI to be used to build the API call, i.e the search keyword.

The following code snippet shows what parameters we want to constrain our image search with:

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);

We just aren't sure how to restrict the number of search results or what format the data returns in. Is it JSON?


Solution

  • This is if you are building a URL, and not doing it programatically.

    • To specify JSON as the return value, append &alt=json to the end of your request URL.
    • To limit the number of searches returned, use num=50 as one of the parameters

    Source: https://developers.google.com/custom-search/v1/using_rest#query-params