Google image search says api no longer available

Md. Parvez Alam picture Md. Parvez Alam · Dec 2, 2015 · Viewed 87.8k times · Source

I am using google image search API. Till yesterday it was working, but today morning it says "This API is no longer available"

Is it officially closed, Or any error at my side

Request

https://ajax.googleapis.com/ajax/services/search/images?v=1.0&rsz=8&q=cute+kittens

Response

{"responseData": null, "responseDetails": "This API is no longer available.", "responseStatus": 403}

Answer

Vijay Shegokar picture Vijay Shegokar · Dec 3, 2015

The answer I found was using Google's Custom Search Engine (CSE) API. Note that this is limited to 100 free requests per day.

Creating cx and modifying it to search for images

  1. Create custom search engine at https://cse.google.com/cse/create/new based on your search criteria.
  2. Choose sites to search (leave this blank if you want to search the entire web, otherwise you can enter a site to search in one particular site)
  3. Enter a name and a language for your search engine.
  4. Click "create." You can now find cx in your browser URL.
  5. Under "Modify your search engine," click the "Control Panel" button. In the "edit" section you will find an "Image Search" label with an ON/OFF button, change it to ON. Click "update" to save your changes.

Conducting a search with the API

The API endpoint url is https://www.googleapis.com/customsearch/v1

The following JSON parameters are used for this API:

  • q: specifies search text
  • num: specifies number of results. Requires an integer value between 1 and 10 (inclusive)
  • start: the "offset" for the results, which result the search should start at. Requires an integer value between 1 and 101.
  • imgSize: the size of the image. I used "medium"
  • searchType: must be set to "image"
  • filetype: specifies the file type for the image. I used `"jpg", but you can leave this out if file extension doesn't matter to you.
  • key: an API key, obtained from https://console.developers.google.com/
  • cx: the custom search engine ID from the previous section

Simply make a GET request by passing above parameters as JSON to the API endpoint (also listed above).

Note: If you set a list of referrers in the search engine settings, visiting the URL via your browser will likely not work. You will need to make an AJAX call (or the equivalent from another language) from a server specified in this list. It will work for only the referrers which were specified in the configuration settings.

Reference: https://developers.google.com/custom-search/json-api/v1/reference/cse/list