Search code examples
twittertwitter-streaming-api

Getting realtime twitter search results using the streaming API


I have an application where I need to get complete, realtime search results from twitter (preferably polling every 500ms or less). Based on my understanding, doing this using the search API will run into rate limits very quickly. However, the streaming API doesn't seem to support getting complete anything (only a 5% sample).

More specifically, I have a search query term which typically comes up with <20 matching tweets per hour, and I would like to be informed of these new tweets within 1-2 seconds, and it is considered a failure if I am not notified within 5 seconds. Due to the relatively low frequency of posting, missing even one tweet is very undesirable.

Is there any way I can realistically do this using twitter API, or is my only choice to write a browser extension to repeatedly refresh the search page?


Solution

  • The answer is "yes". Although you are rate limited (the limit is closer to 1% than 5%), that is only a cutoff based on your query results. Very roughly, you can stream about 60 tweets per second max. In your case, you say you expect under 20 tweets per hour, so you should have no problem getting all those tweets.

    You also require a latency less than 5 seconds. In my experience latency has always been a second or two. I think you should be fine.