Client.favorites isn't returning exactly :count results - sometimes off by 1

28 views
Skip to first unread message

Alex Pelan

unread,
Jun 18, 2014, 4:15:12 PM6/18/14
to twitter-...@googlegroups.com
Here's some test code I wrote:

require "twitter"

client = Twitter::REST::Client.new do |config|
        config.consumer_key = ENV['CONSUMER_KEY']
        config.consumer_secret = ENV['CONSUMER_SECRET']
        config.oauth_token = "14293877-Ncu9b3942RAA9qzdsoDTMoxGSQn0e7hqHsiLUw224"
        config.oauth_token_secret = ENV['ACCESS_TOKEN_SECRET']
end


results = client.favorites("alexpelan", {:count => 200})
p results.count

It prints out "199." If I loop over all of my user's favorites, it sometimes returns 200 and sometimes returns 199 results. Any idea what could be going on here?

sferik

unread,
Jun 18, 2014, 5:33:30 PM6/18/14
to twitter-...@googlegroups.com
From Twitter’s API documentation for the count parameter.

Specifies the number of tweets to try and retrieve, up to a maximum of 200. The value of count is best thought of as a limit to the number of tweets to return because suspended or deleted content is removed after the count has been applied. 

If you need a precise number of results, you can make multiple HTTP requests, counting the results yourself until the target number is reached or Twitter returns an empty collection (no results remain). I’ve written a module that does this for t.

Alex Pelan

unread,
Jun 18, 2014, 5:54:13 PM6/18/14
to twitter-...@googlegroups.com
Thanks for the quick response! That's just what I was looking for. 
Reply all
Reply to author
Forward
0 new messages