我正在尝试从ruby中的Clickbank API提取广告系列统计信息。当我运行提供的示例代码Clickbank时。我收到以下错误:
未初始化的常量Net :: HTTPS(NameError)。我错过了什么?
示例代码。
require 'net/http'
require 'net/https'
http = Net::HTTPS.new('api.clickbank.com')
http.use_ssl = false
path = '/rest/1.3/orders/list'
headers = {
'Authorization' => '<< DEVKEY >>:<< APIKEY>>',
'Accept' => 'application/json'
}
resp, data = http.get(path, nil, headers)
puts 'Code = ' + resp.code
puts 'Message = ' + resp.message
resp.each {|key, val| puts key + ' = ' + val}
puts data
是的,我把我的dev和api密钥放入
答案 0 :(得分:1)
使用Net:HTTP
并启用SSL,而不是使用Net::HTTPS
并禁用SSL。
示例:
http = Net::HTTP.new('api.clickbank.com')
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
答案 1 :(得分:1)
您实际上并不想像API那样禁用ssl。基于http的文档,我能够让它像这样工作:http://ruby-doc.org/stdlib-2.1.1/libdoc/net/http/rdoc/Net/HTTP.html
require 'net/http'
uri = URI('https://api.clickbank.com/rest/1.3/orders/list')
req = Net::HTTP::Get.new(uri)
# set headers on the request
req['Authorization'] = '<< DEVKEY >>:<< APIKEY>>'
req['Accept'] = 'application/json'
# perform the request
resp, data = Net::HTTP.start(uri.hostname, uri.port) {|http|
http.request(req)
}
puts 'Code = ' + resp.code
puts 'Message = ' + resp.message
resp.each {|key, val| puts key + ' = ' + val}
puts data
答案 2 :(得分:1)