使用 Tweepy 获取关注者信息

问题描述

我在使用以下代码获得的列表中列出了所有关注者 ID。现在,我想获取所有这些 ID 的信息(followers_countfriends_countverified 等)。为了每 15 分钟获得 18000 个结果,我需要进行哪些更改。我在 15 分钟内使用以下代码获得了 75000 个 ID。

counter = 0
reset_counter = 0
loop_counter = True
backoff_timer = 2 # counter for timer

while loop_counter:
    try:
        for friend in tweepy.Cursor(api.followers_ids,id='adl440',count=5000).items():
            time.sleep(0.01)
            reset_counter += 1 # reser 1
            # this is reducing the waiting time

            counter += 1 #count 1
            # max collection 5*15K =75K in 15 mins
            # insert the information into the table
            #uid_json = {'uid': friend}
            #collection.insert_one(uid_json)
            # # saving the txt file
            
            print(str(friend))
            csvWriter.writerow(str(friend))
            count +=1
            print(count)

        break

    except tweepy.TweepError as err:
        print(err.reason)
        time.sleep(60 * backoff_timer)
        sleep_time = 60 * backoff_timer
        print('Error Generated by Tweepy API sleep {0} seconds.'.format(round(sleep_time,2)))
        backoff_timer += 1
        continue

我尝试使用 API 查找方法获取数据,但未能成功。每次尝试时,我的输出结果都很少,突然就达到了速率限制。

解决方法

GET users/lookup 使用的 API.lookup_users Twitter API 端点每个请求返回 100 个用户。端点的速率限制为 900 个请求/15 分钟。使用用户身份验证和 300 个请求/15 分钟。使用应用程序身份验证。这意味着您应该能够每 15 分钟检索 30,000 或 90,000 个用户。窗口,具体取决于您使用的是应用身份验证还是用户身份验证。