Twitter API is returning HTTP 429 - Too Many Requests

Tanapat Ruengsatra picture Tanapat Ruengsatra · Apr 1, 2013 · Viewed 10.2k times · Source

I make the twiiter application and I make a loop for getting data from twitter API It showed error

[raw] => HTTP/1.1 429 Too Many Requests
[content-type: application/json; charset=utf-8
date: Fri, 29 Mar 2013 20:03:07 UTC
server: tfe
set-cookie: guest_id=v1%3A136458738755627462; Domain=.twitter.com; Path=/; Expires=Sun, 29-Mar-2015 20:03:07 UTC

How can I fix it

Answer

nkr picture nkr · Apr 1, 2013

The Twitter API documentation has a long article about rate-limiting.

15 Minute Windows

Rate limits in version 1.1 of the API are divided into 15 minute intervals, which is a change from the 60 minute blocks in version 1.0. Additionally, all 1.1 endpoints require authentication, so no longer will there be a concept of unauthenticated calls and rate limits.

While in version one of the API, an OAuth-enabled application could initiate 350 GET-based requests per hour per access token, API v1.1's rate limiting model allows for a wider ranger of requests through per-method request limits. There are two initial buckets available for GET requests: 15 calls every 15 minutes, and 180 calls every 15 minutes.

The Rate Limits page shows which resource permits how many requests per 15 minutes.

Make fewer requests in the 15 minute windows. You could cache responses from the API and read data from there instead of refreshing the data by querying the API every time. E.g. do not query the home timeline every time the user clicks on a button but read the cached results from earlier. Then set a timeout for the cache so your cached data doesn't get outdated too much.