This forum is now read-only. Please use our new forums! Go to forums

0 points
Submitted by Bin Diya
about 11 years

Someone help wit ex.4

Someone help wit ex.4 print [“text”] or puts [“text”] doesn’t work as wel

Answer 515424b62a6103025a000a84

6 votes

Permalink

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.

points
Submitted by Philipp Antar
about 11 years

3 comments

Bin Diya about 11 years

Thank u :) I completed

Lu Xie almost 11 years

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?”

Shaikh Wasim about 10 years

Thanks.. I need to learn Ruby ;)

Answer 5155a83a50057bf4b9001422

2 votes

Permalink

def print_timeline(tweets) tweets.each do |tweet| puts tweet[“text”] end

end

points
Submitted by Bin Diya
almost 11 years

Answer 535bcee1631fe9b249001711

1 vote

Permalink

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?

points
Submitted by Ady Beleanu
almost 10 years

Answer 53967c6b80ff33cb7b00052a

0 votes

Permalink

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

points
Submitted by ILU2014
almost 10 years

Answer 53970a2e8c1ccccde600144f

0 votes

Permalink

it worked with Phillip’s approach. Thanks :)

points
Submitted by Ady Beleanu
almost 10 years