2

So, I am testing this piece of code :

import requests
import json


searchTerm = 'parrot'
startIndex = '0'
searchUrl = "http://ajax.googleapis.com/ajax/services/search/images?v=1.0&q=" + \
    searchTerm + "&start=" + startIndex
r = requests.get(searchUrl)
response = r.content.decode('utf-8')
result = json.loads(response)
print(r)
print(result)

And the response is :

<Response [200]>
{'responseData': None, 'responseStatus': 403, 'responseDetails': 'This API is no longer available.'}

Seems that I am trying to use the old API and it is deprecated now. When I check on the Google Custom Search API I don't see any way to search straight on google images, is this even possible with the new API ?

3

1 Answer 1

7

It is possible, here is new API reference:
https://developers.google.com/custom-search/json-api/v1/reference/cse/list

import requests
import json

searchTerm = 'parrot'
startIndex = '1'
key = ' Your API key here. '
cx = ' Your CSE ID:USER here. '
searchUrl = "https://www.googleapis.com/customsearch/v1?q=" + \
    searchTerm + "&start=" + startIndex + "&key=" + key + "&cx=" + cx + \
    "&searchType=image"
r = requests.get(searchUrl)
response = r.content.decode('utf-8')
result = json.loads(response)
print(searchUrl)
print(r)
print(result)

That works fine, I just tried.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for your answer ! I just did myself some hours ago and yeah it works pretty well. You can make nice custom queries, and it is very convenient but the 100 requests per day per user is a bit low :S If you want to use it youself for certain, non necessarily spammy activities, you are going to see yourself having to hack in order to avoid paying.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.