Twitter Rate Limiting - How To Handle

From Hostek.com Wiki
Revision as of 21:47, 5 May 2013 by Jakeh (Talk | contribs) (Use the Twitter REST API)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Background

It is common to want to include a user's Twitter feed on your Web site, and this can easily be done by calling Twitter's anonymous ATOM search URL (eg. http://search.twitter.com/search.atom?q=Hostek). The downside to using this approach is that the anonymous search utility is rate limited to 150 searches per hour per IP. As such, if other sites on your server also call Twitter's anonymous search URL, you may eventually receive an error stating "Clients may not make more than 150 requests per hour."

How to Avoid Twitter's Rate Limits

Caching

The best way to prevent your site from reaching this limit is to cache your calls to Twitter for at least 1-5 minutes. This can be done easily using the ColdFusion (9+) caching functions described in this blog post. If your application is written in PHP, ASP, or .NET a similar approach can be used -- you could simply store the results of the http call in a variable then set a counter for when the variable needs to be updated.

Use the Twitter REST API

Additionally, you may wish to consider using Twitter's REST-based API as it will give you a higher limit for searches. More details on getting started with the Twitter API can be found at Twitter's API Documentation page. More info on getting started integrating your application with Twitter can be found at the Twitter Developers Portal.