This forum is now read-only. Please use our new forums! Go to forums
Someone help wit ex.4
Someone help wit ex.4 print [“text”] or puts [“text”] doesn’t work as wel
Answer 515424b62a6103025a000a84
Try this:
tweets.each do |tweet|
puts tweet['text']
end
It appears that the object tweets
is an array of hashes. You’ll want to access the hash key 'text'
in each of the elements of the array tweets
. Correct me if I’m wrong. This is quite confusing :)
BTW – I couldn’t get the exercise to pass with print
.
Answer 5155a83a50057bf4b9001422
Answer 535bcee1631fe9b249001711
Even if I changed the count to 10 and set the code like this:
baseurl = "https://api.twitter.com"
path = "/1.1/statuses/user_timeline.json"
query = URI.encode_www_form
( "screen_name" => "twitterapi",
"count" => 10, )
address = URI("#{baseurl}#{path}?#{query}")
request = Net::HTTP::Get.new address.request_uri
# Print data about a list of Tweets
def print_timeline(tweets)
# ADD CODE TO ITERATE THROUGH EACH TWEET AND PRINT ITS TEXT
tweets.each do |tweet|
puts tweet["text"]
end
end
I still get the following error: “Ooops, try again. You did not generate the appropriate number of output lines. Did you update the count parameter?”
Is there something wrong?
Answer 53967c6b80ff33cb7b00052a
I passed the exercise.
For this exercise you should be able to open twitter with your browser, Twitter is inaccessible in some countries.
set count to 10 : query = URI.encode_www_form( “screen_name” => “twitterapi”, “count” => 10,
def print_timeline(tweets) tweets.each do |tweet| p tweet[“text”] end end
Answer 53970a2e8c1ccccde600144f
it worked with Phillip’s approach. Thanks :)
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
Thank u :) I completed
Can you help to point out what my problem is? I tried with puts tweet[“user”][“name”]+’ - ‘+tweet[“text”] but it always said “You did not generate the correct output. Did you print the username, followed by ‘ - ‘, followed by the Tweet text?”
Thanks.. I need to learn Ruby ;)