我需要在我的Rails应用程序上与Google Images API对话。有没有Ruby宝石可以做到这一点?我发现了一个使用过时的API的旧gem。
有一个名为google_custom_search_api
的宝石使用较新的谷歌自定义搜索API:https://github.com/wiseleyb/google_custom_search_api
您可以通过为image
参数指定searchType
将其限制为图像搜索,如下所示:
results = GoogleCustomSearchApi.search("poker", {"searchType" => "image"})
另外还有一个名为image_suckr的宝石 - https://github.com/maurimiranda/image_suckr你也可以直接在Google Image Search API中做类似的事情
suckr = ImageSuckr :: GoogleSuckr.new suckr.get_image_url({“q”=>“car”})
您可以使用SerpApi gem来刮取Google图像结果。你必须将tbm
参数设置为ishch
。
例如,要获取海豚图像:
require 'google_search_results'
params = {
q: "Dolphins",
location: "Austin, Texas, United States",
hl: "en",
gl: "us",
google_domain: "google.com",
tbm: "isch",
}
query = GoogleSearchResults.new(params)
hash_results = query.get_hash
有关Google Images API的更多信息:https://serpapi.com/images-results