tweepy - 使用光标时获取剩余的 Twitter api 速率限制

tweepy - get remaining Twitter api rate limit while using cursor

是否可以在使用 tweepy 和 Cursors 时从 Twitter 获取 HTTP 响应 header 的值?

我想知道我的应用程序的当前 API 剩余速率限制,应该在 header 中返回,如 Twitter API docsx-rate-limit-remaining:15分钟剩余的请求数window)

示例代码如下:

import tweepy as tw

for status in tw.Cursor(api.user_timeline, screen_name='@somethingsomething', tweet_mode="extended").items():
    #do something

知道如何实现吗?

non-Tweepy 请求并阅读 header 是唯一的方法吗?

我自己找到了解决方案,所以基本上如果你在 Tweepy 中启用调试:

import tweepy as tw

tw.debug(True)

你会在日志中得到它,例如

header: x-rate-limit-remaining: 138