Tweepy实现避免Twitter速率限制器(Python)

2024-04-23 16:09:53 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试执行以下代码并收到'88'错误,也复制到下面。我已经去掉了twitter帐户句柄,但我包含了25个帐户句柄,每个帐户句柄都有大约3万到8万个追随者(可能平均约为2万)。在

import time
import tweepy
import csv
from itertools import zip_longest

auth = tweepy.OAuthHandler('', '')
auth.set_access_token('', '')

api = tweepy.API(auth)

accounts = [25 twitter account handles here as strings]

numberOfAccts = len(accounts)
d = [[''],[''],[''],[''],[''],[''],[''],[''],[''],[''],[''],[''],[''],[''],[''],[''],[''],[''],[''],[''],[''],[''],[''],[''],['']]

with open('FollowerIDLists.csv', 'a', newline="") as f:
    #writer = csv.writer(f)
    for i in range(0, numberOfAccts):
        print(accounts[i])
        ids = []
        for page in tweepy.Cursor(api.followers_ids, screen_name=accounts[i]).pages():
            ids.extend(page)
            time.sleep(60)
        d[i] = ids
    export_data = zip_longest(*d, fillvalue = '')
    wr = csv.writer(f)
    wr.writerow(accounts)
    wr.writerows(export_data)
f.close()

错误就在这里:

^{pr2}$

我听说避免速率限制器的正确方法是使用“wait”和“wait”的组合,但我不知道如何在上面实现这些。如你所见,我试过时间。睡觉(60)指挥。有谁能帮我一把?在


Tags: csvimportauthidslongesttime错误帐户