0
votes

Using pip3 install twitter for a small Python program to retrieve all user's tweets in total year.

utl = t.statuses.user_timeline(count = n, screen_name = name)

Got a error about rate limits, as it shows:

details: {'errors': [{'code': 88, 'message': 'Rate limit exceeded'}]}

After checking api docs, https://dev.twitter.com/rest/public/rate-limiting, but no idea how to fix it.

Hopefully, anyone could help. Thanks!

1

1 Answers

7
votes

The rate limit page is quite clear, you are restricted to making 180 calls per 15 minutes.

This gives you a few options.

  • Throttle your code. Put a sleep in there to ensure it never exceeds the limit.
  • Use the API options to get the maximum amount of data in the shortest amount of API calls.

The documentation for statuses/user_timeline says:

This method can only return up to 3,200 of a user’s most recent Tweets.

and

count Specifies the number of tweets to try and retrieve, up to a maximum of 200 per distinct request.

So you can use count=200 to request all 3,200 statuses in just 16 API calls.