首页 > 解决方案 > 拉取所有账号推特关注者,目前只能获取5000个ID

问题描述

我已经制作了一个代码,可以使指定 Twitter 帐户的关注者静音,但显然当拉动关注者 ID 时,我只能获得 5000。有没有办法让我继续使用“最后一次看到”方法或光标拉更多?

import tweepy
import time

consumer_key = *****
consumer_secret = *****
key = *****
secret = *****

auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(key, secret)
api = tweepy.API(auth, wait_on_rate_limit=True)
user_name = 'realdonaldtrump'

def mute():
    muted_users = api.mutes_ids() 
    followers = api.followers_ids(user_name)
    try:
        for x in followers:
            if x in muted_users :
                pass
            else:
                api.create_mute(x)
                time.sleep(5)
    except Exception:
        print('Error')

标签: twittercursortweepytwitterapi-python

解决方案


是的,这个函数确实支持游标。从Tweepy 示例中,您可以像这样使用它们 - 您需要修改它以静音而不是跟随。

for follower in tweepy.Cursor(api.followers).items():
    follower.follow()

对于拥有大量关注者的帐户,您会遇到的问题是这里的速率限制很低 - 15 分钟内调用 15 次 - 所以这将需要很长时间才能完成。您还可以达到在一段时间内可以静音的帐户数量的帐户限制。


推荐阅读