简体   繁体   中英

Is there a Ruby gem to use the Google Images API?

I need to talk with the Google Images API on my Rails Application. Is there a Ruby gem to do this? I found an old gem that used the deprecated API.

There is a gem called google_custom_search_api that uses the newer google custom search API: https://github.com/wiseleyb/google_custom_search_api

You can limit this to image search by specifying image for the searchType parameter, like so:

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

Also there is another gem called image_suckr - https://github.com/maurimiranda/image_suckr also you can do somthing similar directly in Google Image Search API

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

You can use SerpApi gem to scrape Google Images results. You'll have to set tbm parameter set as ishch .

For example, to fetch dolphins images:

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

More information about the Google Images API: https://serpapi.com/images-results

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM