tweepy:get_user的速率限制与twitter api的速率限制不同

时间:2019-09-12 22:47:17

标签: tweepy

看起来像

API.get_user(id/user_id/screen_name)

tweepy

的总结
GET users/lookup
在Twitter API中

Twittter docGET users/lookup的速率限制为

  

每个请求100个用户,900个请求/ 15分钟

当我使用API.get_user(id/user_id/screen_name)时,速率限制似乎是900位用户/ 15分钟。是因为tweepy每个请求仅发送一个用户,还是我的代码没有针对批处理进行优化?

我的代码:

import numpy as np
import pandas as pd
import tweepy


auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth, wait_on_rate_limit=True, wait_on_rate_limit_notify=True)


df_followers = pd.read_csv(r"3_follower_id_temp.csv")        

# make list of the index (use in loop)
ind = list( range(0, len(df_followers), 50) )
ind.append(len(df_followers))

l_followers_info = []
l_failed = []


for ii in range(len(ind) - 1):

    print(ind[ii], ind[ii+1])

    try: # some user id do not exist and will throw error
        temp = [api.get_user(id = ff)._json for ff in df_followers.follower_id[ind[ii] : ind[ii+1]]]
        l_followers_info.extend(temp)
    except:
        l_failed.extend(list(range(ind[ii], ind[ii+1]))) # keep record of the index of those failed

我怎么知道实际的速率限制是900个用户/ 15分钟:控制台会显示:

0 50
50 100
100 150
150 200
...


850 900
Rate limit reached. Sleep for xxx

达到速率限制后,将自动通过tweepy睡眠xxx。

0 个答案:

没有答案