简体   繁体   中英

tweepy - get remaining Twitter api rate limit while using cursor

Is it possible to get value of HTTP response header from Twitter while using tweepy and Cursors?

I want to know the current API remaining rate limit for my app which should be returned in the header as stated in Twitter API docs ( x-rate-limit-remaining: the number of requests left for the 15 minute window )

Example code below:

import tweepy as tw

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

Any idea how to achieve this?

Is doing non-Tweepy request and read the headers the only way?

Found solution on my own, so basically if you enable debug in Tweepy:

import tweepy as tw

tw.debug(True)

you'll get it in the logs, for ex.

header: x-rate-limit-remaining: 138

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM