6

Trying to find out how to do Google image searches via an API / REST call. Apparently the image search API is deprecated and directs us to the Custom Search API.

But my first experiments with the Custom Search API, return results from my own website !!&*%%%$@@!, which is not helpful in the slightest.

I need image results from Google images. Anyone have an example query that works?

Kara
  • 6,115
  • 16
  • 50
  • 57
Fraggle
  • 8,607
  • 7
  • 54
  • 86

1 Answers1

10

You will basically want to generate a URL like this. Note the search type parameter at the end.

https://www.googleapis.com/customsearch/v1?key=YOUR API KEY&cx=YOUR CUSTOM SEARCH ENGINE IDENTIFIER&q=your query&searchType=image

You can read more here https://developers.google.com/custom-search/json-api/v1/using_rest

edit: changed searchType to lowercase based on comment below

Jun Wei Lee
  • 1,002
  • 11
  • 25
  • 1
    `{ "error": { "errors": [ { "domain": "global", "reason": "invalid", "message": "Invalid Value" } ], "code": 400, "message": "Invalid Value" } }` – shariful islam Aug 21 '18 at 13:09
  • It should be `&searchType=image` lowercase `i` – Izzy Nov 10 '19 at 20:36
  • Anyone looking to get their custom search engine id (cx) should go to here: https://cse.google.com/cse/all – Darrow Hartman Jun 14 '20 at 03:59
  • 1
    as advised by Marc, "To do this you need to click "Enable image search" in your CSE console!" https://stackoverflow.com/questions/8448788/google-custom-search-for-images-only?rq=1#comment19525760_12696898 ... I spent a whole hour troubleshooting til i found his comment on a related thread. – olisteadman Jun 15 '20 at 13:14