Skip to content

Instantly share code, notes, and snippets.

@williamho
Created December 5, 2015 02:08
Show Gist options
  • Select an option

  • Save williamho/9b67275d30cd79f2280c to your computer and use it in GitHub Desktop.

Select an option

Save williamho/9b67275d30cd79f2280c to your computer and use it in GitHub Desktop.
# In Gemfile:
# gem 'google-api-client', '0.9.pre3'
require 'google/apis/customsearch_v1'
Customsearch = Google::Apis::CustomsearchV1
search = Customsearch::CustomsearchService.new
# https://cse.google.com/cse/all
# Click name of CSE to edit
# Image search => On
# Sites to search => Search the entire web but emphasize included sites
search.key = 'insert here'
# Details: Search Engine ID
cx = 'insert here'
search_term = 'snow'
results = search.list_cses(
search_term,
cx: cx,
search_type: 'image'
)
puts results.items.sample.link
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment