使用ruby访问https上的apis

时间:2012-09-12 18:36:28

标签: ruby api ssl https google-api

我正在编写一个脚本,使用google shopping api进行价格跟踪。当我使用curl或网络浏览器点击此网址时,它会加载数据。

https://www.googleapis.com/shopping/search/v1/public/products?key=AIzaSyC24EXbQZ1X7KmaKLJ-Bd9SKgOx4x9ob-M&country=US&q=digital+camera

但是,当我使用这个ruby脚本时

require "rubygems"
require "net/https"

@url = 'https://www.googleapis.com/shopping/search/v1/public/products?key=AIzaSyCGGKfldgrPQsXAJw5Dbn1M3QWZ9vqVyBQ&country=US&q=digital+camera'
uri = URI.parse @url
http = Net::HTTP.new(uri.host, 443)
http.use_ssl = true 
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
http.ca_file = File.join(File.dirname(__FILE__), "./cacert.pem")
http.start { http.request_get(uri.path) {|res| print res.body } }

我收到此错误:

"error": {
  "errors": [
   {
    "domain": "usageLimits",
    "reason": "dailyLimitExceededUnreg",
    "message": "Daily Limit Exceeded. Please sign up",
    "extendedHelp": "https://code.google.com/apis/console"
   }
  ],
  "code": 403,
  "message": "Daily Limit Exceeded. Please sign up"
 }
}

我的理论是,错误来自我的ruby代码如何使用https不正确。 cacert.pem来自curl.haxx.se/ca/cacert.pem 要通过https访问api,我需要做什么?

1 个答案:

答案 0 :(得分:0)

该错误对我来说看起来很不言自明。每日限额是多少?你有多少请求?