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 ?

xavier
  • 746
  • 2
  • 12
  • 22
  • As far as I know it is not possible without creating a search engine. But maybe this question is helpful http://stackoverflow.com/questions/10141800/google-search-by-image-api (have a look at argonius's answer) – exilit Feb 25 '16 at 09:09
  • What I want to do is to search an image by text query, not by image ! – xavier Feb 25 '16 at 09:17
  • Try this: https://www.google.de/search?q=stackoverflow&tbm=isch – exilit Feb 25 '16 at 09:20

1 Answers1

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.

galeksic
  • 2,176
  • 18
  • 25
  • 2
    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. – xavier Feb 25 '16 at 18:06