Google api 谷歌图像搜索称api不再可用
我正在使用谷歌图像搜索API。直到昨天它还在工作,但今天早上它说“这个API不再可用” 它是正式关闭的,还是我这边有任何错误 请求 响应Google api 谷歌图像搜索称api不再可用,google-api,google-image-search,Google Api,Google Image Search,我正在使用谷歌图像搜索API。直到昨天它还在工作,但今天早上它说“这个API不再可用” 它是正式关闭的,还是我这边有任何错误 请求 响应 {"responseData": null, "responseDetails": "This API is no longer available.", "responseStatus": 403} 将API url更改为 提供与API密钥和CX相同的参数 将API url更改为 提供与API密钥和CX相同的参数 这是要使用的完整URL模板 我们可以
{"responseData": null, "responseDetails": "This API is no longer available.", "responseStatus": 403}
将API url更改为
提供与API密钥和CX相同的参数
将API url更改为
提供与API密钥和CX相同的参数
这是要使用的完整URL模板 我们可以消除不必要的参数。 {searchTerms}&num={count?}&start={startIndex?}&lr={language?}&safe={safe?}&cx={cx?}&cref={cref?}&sort={sort?}&filter={filter}&gl gl gl}&cr={cr?}&googlehost={googlehost?}&c2ccoff={disableCnTwTranslation}&chq={hq}&hl hl hl hl hl chl={siteSearch={siteSearch={siteSearch={filter}&sitesarch={siteSearch}&screerch}&screerch}&screerch}&screerch={screerch}&screerch}&scr={linkSite?}&orTerms={orTerms?}&relatedSite={relatedSite?}&dateRestrict={dateRestrict?}&lowRange={lowRange?}&highRange={highRange?}&searchType={searchType}&fileType={fileType?}&rights={rights}&imgSize={imgType={imgType?}&imgColorType={imgColorType?}&imgDominantColor={imgDominantColor}&json= 我正在使用
这是要使用的完整URL模板 我们可以消除不必要的参数。 {searchTerms}&num={count?}&start={startIndex?}&lr={language?}&safe={safe?}&cx={cx?}&cref={cref?}&sort={sort?}&filter={filter}&gl gl gl}&cr={cr?}&googlehost={googlehost?}&c2ccoff={disableCnTwTranslation}&chq={hq}&hl hl hl hl hl chl={siteSearch={siteSearch={siteSearch={filter}&sitesarch={siteSearch}&screerch}&screerch}&screerch}&screerch={screerch}&screerch}&scr={linkSite?}&orTerms={orTerms?}&relatedSite={relatedSite?}&dateRestrict={dateRestrict?}&lowRange={lowRange?}&highRange={highRange?}&searchType={searchType}&fileType={fileType?}&rights={rights}&imgSize={imgType={imgType?}&imgColorType={imgColorType?}&imgDominantColor={imgDominantColor}&json= 我正在使用
看来我们需要实现谷歌定制搜索API
在您自己提供的页面顶部这样说看起来我们需要实现谷歌定制搜索API
在你自己提供的页面顶部这样说我找到的答案是使用谷歌的定制搜索引擎(CSE)API。请注意,这限制为每天100个免费请求 创建
cx
并修改它以搜索图像
cx
:指定搜索文本q
:指定结果数。需要介于1和10(含)之间的整数值num
:结果的“偏移量”,搜索应从哪个结果开始。需要一个介于1和101之间的整数值start
:图像的大小。我使用了imgSize
“中等”
:必须设置为searchType
“image”
:指定图像的文件类型。我使用了“jpg”,但如果文件扩展名对您不重要,您可以忽略此选项filetype
:从密钥
:上一节中的自定义搜索引擎IDcx
GET
请求
注意:如果您在搜索引擎设置中设置了一个引用者列表,那么通过浏览器访问URL可能不起作用。您需要进行AJAX调用(或使用其他语言的等效调用)来自此列表中指定的服务器。它仅适用于配置设置中指定的引用者
参考:
我找到的答案是使用谷歌的定制搜索引擎(CSE)API。请注意,这限制为每天100个免费请求 创建
cx
并修改它以搜索图像
cx
:指定搜索文本q
:指定结果数。需要介于1和10(含)之间的整数值num
:结果的“偏移量”,搜索应从哪个结果开始。需要一个介于1和101之间的整数值start
:图像的大小。我使用了imgSize
“中等”
:必须设置为searchType
“image”
:指定图像的文件类型。我使用了`“jpgfiletype
public static String FindImage(String question, String ua) { String finRes = ""; try { String googleUrl = "https://www.google.com/search?tbm=isch&q=" + question.replace(",", ""); Document doc1 = Jsoup.connect(googleUrl).userAgent(ua).timeout(10 * 1000).get(); Element media = doc1.select("[data-src]").first(); String finUrl = media.attr("abs:data-src"); finRes= "<a href=\"http://images.google.com/search?tbm=isch&q=" + question + "\"><img src=\"" + finUrl.replace(""", "") + "\" border=1/></a>"; } catch (Exception e) { System.out.println(e); } return finRes; }
https://www.googleapis.com/customsearch/v1?key=SERVER_KEY&cx=CUSTOM_SEARCH_ID&q=flower&searchType=image&fileType=jpg&imgSize=xlarge&alt=json
<html lang="pt"> <head> <title>JSON Custom Search API Example</title> </head> <body> <div id="content"></div> <script> function hndlr(response) { console.log(response); for (var i = 0; i < response.items.length; i++) { var item = response.items[i]; // in production code, item.htmlTitle should have the HTML entities escaped. document.getElementById("content").innerHTML += "<br>" + item.htmlTitle; } } </script> <script src="https://www.googleapis.com/customsearch/v1?key=API_KEY&cx=SEARCH_ENGINE_KEY&q=flower&searchType=image&callback=hndlr"></script> </body> </html>