The 'count' parameter


#1

Is this a bug? Everything seems to be working well in the console output, but i still get an error "You did not generate the appropriate number of output lines. Did you update the 'count' parameter?". I've even checked the number of output by using puts tweet.count which gives 10, but still i can't get through. here is my full code.

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

# Now you will fetch /1.1/statuses/user_timeline.json,
# returns a list of public Tweets from the specified
# account.
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

# 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
tweets = nil
if response.code == '200' then
  tweets = JSON.parse(response.body)
  print_timeline(tweets)
end
nil

#2

The tweets variable is holding all the tweets. To see what it looks like just use 'puts tweets'. You will find that it is not holding objects, but strings. So there is no need to use tweet['text']

Your loop should be tweets.each { |tweet| puts tweet }

Let me know if that worked for you.


#3

it worked well, thanks


#4

It worked for me too, but the hint shows an use of tweets.each
Thanks!