Saliceran
Saliceran

Reputation: 350

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?

Upvotes: 2

Views: 2349

Answers (2)

pbojinov
pbojinov

Reputation: 927

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

Upvotes: 1

Kenneth
Kenneth

Reputation: 28747

The following page has all the documentation for the Google custom search API:

https://developers.google.com/custom-search/v1/overview

At a first glance I can see it's a JSON / atom api. So I guess probably the default return format is JSON and through content negotation you can also request atom (but again, please read the documentation to be sure).

Upvotes: 0

Related Questions