This forum is now read-only. Please use our new forums at discuss.codecademy.com.

Introduction to Twitter's API Forum

View Course » View Exercise

1320 points
539a205f80ff3355e500047f_154839034
Submitted by
Michael
about 2 years ago

I've tried everything, but nothing works!

I am being driven up the wall with this exercise. I have looked through every post regarding this lesson, have tried every example, but nothing, and I repeat NOTHING is working!

Here is my code:

require 'rubygems'
require 'oauth'
require 'json'

baseurl = "https://api.twitter.com"
path = "/1.1/statuses/show.json"
query = URI.encodewwwform("id" => "266270116780576768")
address = URI("#{baseurl}#{path}?#{query}")
request = Net::HTTP::Get.new address.request_uri

def print_tweet(tweet)
# ADD CODE TO PRINT THE TWEET IN " - " FORMAT
puts tweet["user"]["name"] + " - " + tweet["text"]
end

http = Net::HTTP.new address.host, address.port
http.usessl = true
http.verify
mode = OpenSSL::SSL::VERIFY_PEER

consumerkey ||= OAuth::Consumer.new "ENTER IN EXERCISE 1", ""
access
token ||= OAuth::Token.new "ENTER IN EXERCISE 1", ""

request.oauth! http, consumerkey, accesstoken
http.start
response = http.request request

tweet = nil
if response.code == '200' then
tweet = JSON.parse(response.body)
print_tweet(tweet)
end

If there is something wrong with this code, please tell me quick. I want to get through this lesson, and it's driving me crazy how nothing works.