对不起,如果这很明显,我只有大约 5 天的 ruby 经验。我正在尝试将 Twitter 上的前 10 个热门话题写入 json 文件。API 请求是对https://api.twitter.com/1/trends/1.json的 GET 请求。我的代码是
require "net/http"
require "uri"
require "JSON"
uri = URI.parse("https://api.twitter.com/1/trends/1.json")
File.open("test.json", "w") do |f|
f.write(Net::HTTP.get(uri.host, uri.port))
end
它给了我一个错误
D:/Program Files/ruby-1.9.2/lib/ruby/1.9.1/net/http.rb:1668:in 'initialize': undefined method 'empty?' for 443:Fixnum (NoMethodError) from
D:/Program Files/ruby-1.9.2/lib/ruby/1.9.1/net/http.rb:1787:in 'intialize' from
D:/Program Files/ruby-1.9.2/lib/ruby/1.9.1/net/http.rb:1081:in 'new' from D:/Program Files/ruby-1.9.2/lib/ruby/1.9.1/net/http.rb:1081:in 'request_get' from
D:/Program Files/ruby-1.9.2/lib/ruby/1.9.1/net/http.rb:389:in 'block in get_response' from
D:/Program Files/ruby-1.9.2/lib/ruby/1.9.1/net/http.rb:627:in 'start' from
D:/Program Files/ruby-1.9.2/lib/ruby/1.9.1/net/http.rb:388:in 'get_response' from
D:/Program Files/ruby-1.9.2/lib/ruby/1.9.1/net/http.rb:370:in 'get' from test:8:in 'block in (main)'
对此的任何帮助都会很棒
编辑: https ://dev.twitter.com/docs/api/1/get/trends/%3Awoeid是如果我错过提供任何重要信息,我正在使用的 API 调用的所有信息