Twitter搜索API - Ruby

时间:2014-08-14 21:08:02

标签: ruby api twitter

我试图利用Twitter API返回20条包含单词房地产的最新推文。脚本执行但不返回任何数据。有任何想法吗?我把SSSL作为VERIFY :: PEER,但遇到了我想绕过的证书问题。

require 'rubygems'

require 'oauth'
require 'json'


baseurl = "https://api.twitter.com"
path    = "/1.1/search/tweets.json?src=typd&q=real%20estate%20capital"
query   = URI.encode_www_form(

    "count" => 20,
)

address = URI("#{baseurl}#{path}?#{query}")
request = Net::HTTP::Get.new address.request_uri

# Print data about a Tweet
def print_tweet(tweets)
tweets.each do |tweet| puts tweet["text"]
end
end

# Set up HTTP.
http             = Net::HTTP.new address.host, address.port
http.use_ssl     = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE

consumer_key ||= OAuth::Consumer.new "", ""
access_token ||= OAuth::Token.new "", ""

# Issue the request.
request.oauth! http, consumer_key, access_token
http.start
response = http.request request

# Parse and print the Tweet if the response code was 200
tweets = nil
if response.code == '200' then
tweets = JSON.parse(response.body)
print_tweet(tweets)
end
nil

0 个答案:

没有答案