Retrieving the # of tweets containing a certain string


Hi there,

I’m trying to figure out the proper way to retrieve the number of tweets containing a particular string on a particular date, without having to retrieve all of the other data about those tweets.

Because I was sometimes getting back thousands of tweets using the Twitter gem, I decided to switch to just making HTTParty requests to see if that would speed things up.

base_uri = ''
test_uri = '?q=TWTR%20since%3A2014-09-08%20until%3A2014-09-09'
uri = base_uri + test_uri

response = HTTParty.get(uri,
  :headers => {'Authorization' => bearer}
tweet_count = response['statuses'].count   #=> 15

Here is my request, but now I am limited to 15 tweets as opposed to the thousands that I used to get using the Twitter gem.

I know I can do things to get this rate limit increased to 100 tweets, but is there a way to simply just retrieve the number of tweets without having to get all of the tweets themselves?

Having to get all of the tweets in their entirety leads my application to timeout and crash.

Thanks very much for reading! Any suggestions greatly appreciated.


We don’t have an API for just counting Tweets, I’m afraid. You have to grab the Tweets themselves and count them.

Note, though, that the Search API is “focused on relevance not completeness”. You may not get fully accurate counts this way.


Thanks for your reply Isaac. I’m only concerned with relative figures, so hopefully the Search API is consistent in its inaccuracies?

Anyhow, this explains the weird figure I was getting using the gem.

Is there a different API that would better suit my needs?


The statuses/filter streaming API would allow you to get accurate counts, but only on a go-forward basis. There’s no historical component to it, if you see what I mean.


Oh interesting. Thanks for your clarification!