如何解决 twitter api 速率限制?

How to resolve twitter api rate limit?

使用 pip3 install twitter 的小型 Python 程序检索全年所有用户的推文。

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

收到有关速率限制的错误,如图所示:

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

检查 api 文档后,https://dev.twitter.com/rest/public/rate-limiting,但不知道如何修复它。

希望有人能提供帮助。谢谢!

rate limit page说的很清楚,每15分钟只能拨打180次

这为您提供了一些选择。

  • 限制你的代码。在那里放一个 sleep 以确保它永远不会超过限制。
  • 使用 API 选项在最短的 API 次调用中获取最大量的数据。

documentation for statuses/user_timeline 说:

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

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

因此您可以使用 count=20016 API 调用 .

中请求所有 3,200 个状态