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