使用新的自定义搜索 API 在 Google 张图片上搜索图片?

Search image on Google images with the new Custom Search API?

所以,我正在测试这段代码:

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)

响应是:

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

我似乎在尝试使用旧的 API,现在已弃用它。当我检查 Google Custom Search API 时,我没有看到任何直接搜索 google 图像的方法,这甚至可以使用新的 API 吗?

有可能,这里是新的API参考:
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)

很好用,我刚刚试过了。