twitter - 拉取所有账号推特关注者,目前只能获取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')
解决方案
是的,这个函数确实支持游标。从Tweepy 示例中,您可以像这样使用它们 - 您需要修改它以静音而不是跟随。
for follower in tweepy.Cursor(api.followers).items():
follower.follow()
对于拥有大量关注者的帐户,您会遇到的问题是这里的速率限制很低 - 15 分钟内调用 15 次 - 所以这将需要很长时间才能完成。您还可以达到在一段时间内可以静音的帐户数量的帐户限制。
推荐阅读
- powershell - 如何用数组替换属性对象的值(powershell)
- javascript - 在谷歌地图上使用 mysql 和 php
- r - 如何修改我的代码,以使不同的股票价格与不同的随机数一起使用
- python - 是否需要 deepcopy 从本地对象复制数据
- java - Java:处理非常长的包中的许多相同命名的类
- logging - .Net 核心记录器配置
- html - 元主题颜色在 Android Chrome 中没有暗模式
- reactjs - 我如何有条件地在材料表中设置一行
- json - System.Text.Json 反序列化空值
- apache-spark - 将数据帧结果插入配置单元表时出现火花异常