【问题标题】:Accessing apis over https with ruby使用 ruby​​ 通过 https 访问 api
【发布时间】:2012-09-12 18:36:27
【问题描述】:

我正在编写一个脚本来使用谷歌购物 api 进行价格跟踪。当我用 curl 或网络浏览器点击这个 url 时,它会加载数据。

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?

【问题讨论】:

    标签: ruby api ssl https google-api


    【解决方案1】:

    这个错误在我看来是不言自明的。每日限额是多少?你提出了多少请求?

    【讨论】:

    • 自昨天注册以来,我已经提出了 8 个请求。每日限制为每天 2.5k 请求,每秒限制 1 个请求。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多