そのため、ツイートを Twitter から取り出そうとしています (これは、Twitter Gem を使用できない課題であるため注意してください)。かなり混乱しています。必要なツイートを JSON 文字列の形式で取得できますが、そこからどこへ行くべきかわかりません。私が行っている Twitter API 呼び出しが一連の Tweet オブジェクトを含む JSON 配列を返すことはわかっていますが、ツイート オブジェクトを取得する方法がわかりません。JSON.parse を試しましたが、必要なデータを取得できませんでした (それが何を返すかわかりません)。これが私がこれまでに持っているコードです。私が何をしようとしているのかをコメント/文字列でかなり明確にしました。私はRailsに非常に慣れていないので、これは私がやろうとしていることとはかけ離れているかもしれません.
def get_tweets
require 'net/http'
uri = URI("http://search.twitter.com/search.json?q=%23bieber&src=typd")
http = Net::HTTP.new(uri.host, uri.port)
request = Net::HTTP::Get.new(uri.request_uri)
response = http.request(request)
case response
when Net::HTTPSuccess then #to get: text -> "text", date: "created_at", tweeted by: "from_user", profile img url: "profile_img_url"
JSON.parse(response.body)
# Here I need to loop through the JSON array and make n tweet objects with the indicated fields
t = Tweet.new(:name => "JSON array item i with field from_user", :text "JSON array item i with field text", :date => "as before" )
t.save
when Net::HTTPRedirection then
location = response['location']
warn "redirected to #{location}"
fetch(location, limit - 1)
else
response.value
end
end
ありがとう!