Google Search API ruby

Sou*_*dal 4 ruby ruby-on-rails google-api

我正在使用rails 2.3.我的要求是从Google搜索查询获得前20个链接.

我想使用 http://rubygems.org/gems/google-api-client gem.

但我无法找到任何适当的文档来进行自定义谷歌搜索与身份验证.任何人都能指出一个例子,我可以从中了解如何使用google-api-client gem进行自定义谷歌搜索?

Jer*_*mie 6

如果有人偶然发现这个,这是此代码的更新版本:

的Gemfile

gem 'google-api-client', '~> 0.11'
Run Code Online (Sandbox Code Playgroud)

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
Run Code Online (Sandbox Code Playgroud)

希望这可以帮助!