是否有Ruby gem使用Google Images API?

时间:2012-02-07 19:56:17

标签: ruby ruby-on-rails-3 gem

我需要在我的Rails应用程序上与Google Images API对话。有没有Ruby宝石可以做到这一点?我发现了一个旧的gem,它使用了弃用的API。

3 个答案:

答案 0 :(得分:8)

有一个名为google_custom_search_api的宝石使用较新的Google自定义搜索API: https://github.com/wiseleyb/google_custom_search_api

您可以为image参数指定searchType,将其限制为图片搜索,如下所示:

 results = GoogleCustomSearchApi.search("poker", {"searchType" => "image"})

答案 1 :(得分:1)

另外还有另一个名为 image_suckr 的宝石 - https://github.com/maurimiranda/image_suckr你也可以直接在Google Image Search API中做类似的事情

  

suckr = ImageSuckr :: GoogleSuckr.new
  suckr.get_image_url({“q”=>“car”})

答案 2 :(得分:0)

您可以使用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

相关问题