This forum is now read-only. Please use our new forums! Go to forums
banner
Close banner
Code fulfills conditions for Reading a Tweet 5/3 Twitter API but doesn't pass
Hi, my code fulfils the required conditions but doesn’t pass the test so I rewrote it and just copy pasta-d some answers I found here and it still doesn’t work. My answer is in the correct format and I see no issues with it. Cheers for the help.
require 'rubygems'
require 'oauth'
require 'json'
# Now you will fetch /1.1/statuses/show.json, which
# takes an 'id' parameter and returns the
# representation of a single Tweet.
baseurl = "https://api.twitter.com"
path = "/1.1/statuses/show.json"
query = URI.encode_www_form("id" => "266270116780576768")
address = URI("#{baseurl}#{path}?#{query}")
request = Net::HTTP::Get.new address.request_uri
# Print data about a Tweet
def print_tweet(tweet)
puts tweet["user"]["name"] + " - " + tweet["text"]
end
# Set up HTTP.
http = Net::HTTP.new address.host, address.port
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
# If you entered your credentials in the first
# exercise, no need to enter them again here. The
# ||= operator will only assign these values if
# they are not already set.
consumer_key ||= OAuth::Consumer.new "ENTER IN EXERCISE 1", ""
access_token ||= OAuth::Token.new "ENTER IN EXERCISE 1", ""
# 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
tweet = nil
if response.code == '200' then
tweet = JSON.parse(response.body)
print_tweet(tweet)
end
Answer 53a484d4282ae3a75300006f
14 votes
The user name has changed. Just use: puts “Raffi Krikorian” + “ - “ + tweet[“text”]
Popular free courses
- Free Course
Learn SQL
In this SQL course, you'll learn how to manage large datasets and analyze real data using the standard data management language.Beginner friendly,4 LessonsLanguage Fluency - Free Course
Learn JavaScript
Learn how to use JavaScript — a powerful and flexible programming language for adding website interactivity.Beginner friendly,11 LessonsLanguage Fluency - Free Course
Learn HTML
Start at the beginning by learning HTML basics — an important foundation for building and editing web pages.Beginner friendly,6 LessonsLanguage Fluency
3 comments
Cheers for the help :D
This was so frustrating. Thanks for providing an answer. I wish the instructions would be updated.
Can’t believe this ….