Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Search API ruby

I am using rails 2.3. My requirement is to get the top 20 links from Google search of a query.

I want to use the http://rubygems.org/gems/google-api-client gem.

But I am not able to find any proper documentation for doing custom google search with authentication. Can any one point me to an example, from where I can understand how to use the google-api-client gem for custom google search?

like image 708
Souman Mandal Avatar asked Dec 27 '22 00:12

Souman Mandal


1 Answers

If anyone stumble on this, this is an updated version of this code:

Gemfile

gem 'google-api-client', '~> 0.11'

search.rb

require 'google/apis/customsearch_v1'
Search = Google::Apis::CustomsearchV1
search_client = Search::CustomsearchService.new
search_client.key = 'YOUR API KEY'
response = search_client.list_cses('your query', {cx: 'Search Engine ID'})
status, headers, body = response

pp status
pp headers
pp body

Hope this helps!

like image 51
Jeremie Avatar answered Jan 07 '23 01:01

Jeremie