【问题标题】:Pulling all of an accounts Twitter followers, currently can only get the 5000 IDs拉取所有账号推特关注者,目前只能获取5000个ID
【发布时间】:2021-03-07 05:15:04
【问题描述】:

我已经编写了一个代码,可以使指定 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')

【问题讨论】:

标签: twitter cursor tweepy twitterapi-python


【解决方案1】:

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

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-04-07
    • 1970-01-01
    • 1970-01-01
    • 2013-06-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多