使用Ruby、REST获取对twitter API的请求
我尝试使用Twitter API学习Ruby中的REST 据我所知,我必须写一封GET请求信 我的Ruby代码是:使用Ruby、REST获取对twitter API的请求,ruby,json,api,rest,twitter,Ruby,Json,Api,Rest,Twitter,我尝试使用Twitter API学习Ruby中的REST 据我所知,我必须写一封GET请求信 我的Ruby代码是: require 'rubygems' require 'rest-client' require 'json' url = 'http://api.twitter.com/1/trends.json' response = RestClient.get(url) puts response.body 但我还有下一个错误: /home/danik/.rvm/gems
require 'rubygems'
require 'rest-client'
require 'json'
url = 'http://api.twitter.com/1/trends.json'
response = RestClient.get(url)
puts response.body
但我还有下一个错误:
/home/danik/.rvm/gems/ruby-1.9.3-p194/gems/rest-client-1.6.7/lib/restclient /abstract_response.rb:48:in `return!': 404 Resource Not Found (RestClient::ResourceNotFound)
from /home/danik/.rvm/gems/ruby-1.9.3-p194/gems/rest-client-1.6.7/lib/restclient/request.rb:230:in `process_result'
from /home/danik/.rvm/gems/ruby-1.9.3-p194/gems/rest-client-1.6.7/lib/restclient/request.rb:178:in `block in transmit'
from /home/danik/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/net/http.rb:745:in `start'
from /home/danik/.rvm/gems/ruby-1.9.3-p194/gems/rest-client-1.6.7/lib/restclient/request.rb:172:in `transmit'
from /home/danik/.rvm/gems/ruby-1.9.3-p194/gems/rest-client-1.6.7/lib/restclient/request.rb:64:in `execute'
from /home/danik/.rvm/gems/ruby-1.9.3-p194/gems/rest-client-1.6.7/lib/restclient/request.rb:33:in `execute'
from /home/danik/.rvm/gems/ruby-1.9.3-p194/gems/rest-client-1.6.7/lib/restclient.rb:68:in `get'
from TwitterTrends.rb:5:in `<main>'
/home/danik/.rvm/gems/ruby-1.9.3-p194/gems/rest-client-1.6.7/lib/restclient/abstract_response.rb:48:in'return!':404未找到资源(RestClient::ResourceNotFound)
from/home/danik/.rvm/gems/ruby-1.9.3-p194/gems/rest-client-1.6.7/lib/restclient/request.rb:230:在“过程\结果”中
from/home/danik/.rvm/gems/ruby-1.9.3-p194/gems/rest-client-1.6.7/lib/restclient/request.rb:178:在“传输中的块”中
from/home/danik/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/net/http.rb:745:in'start'
from/home/danik/.rvm/gems/ruby-1.9.3-p194/gems/rest-client-1.6.7/lib/restclient/request.rb:172:在“传输”中
from/home/danik/.rvm/gems/ruby-1.9.3-p194/gems/rest-client-1.6.7/lib/restclient/request.rb:64:in'execute'
from/home/danik/.rvm/gems/ruby-1.9.3-p194/gems/rest-client-1.6.7/lib/restclient/request.rb:33:in'execute'
from/home/danik/.rvm/gems/ruby-1.9.3-p194/gems/rest-client-1.6.7/lib/restclient.rb:68:in'get'
来自TwitterTrends.rb:5:in`'
出了什么问题?由于您试图使用
http://api.twitter.com/1/trends.json
不存在,如本文件所述
此方法已被弃用,并已被GET trends/:woeid替换。
请使用新端点更新应用程序
您想获取如下https://api.twitter.com/1/trends/1.json
。因此,在您的代码中,尝试执行以下操作:
require 'rubygems'
require 'rest-client'
require 'json'
url = 'https://api.twitter.com/1/trends/1.json'
response = RestClient.get(url)
puts response.body
你应该得到回应