Tweepy 检查被阻止的用户?

Tweepy Check Blocked User?

有没有像 is_blocked 方法一样检查用户是否被阻止的方法?我现在设置它的方式是获取我被阻止的用户的列表并将推文的作者与列表进行比较,但它非常低效,因为它经常遇到速率限制。

相关代码:

blocked_screen_names = [b.screen_name for b in tweepy.Cursor(api.blocks).items()]

for count, tweet in enumerate(tweepy.Cursor(api.search, q = query, lang = 'en', result_type = 'recent', tweet_mode = 'extended').items(500)):
                    
        if tweet.user.screen_name in blocked_screen_names:
                continue

不,您必须按照当前的方式进行操作。

(另外,请注意,您最好通过帐户 ID 而不是屏幕名称来检查被阻止的用户,因为此值不会更改,而用户的屏幕名称可以)

为了将来参考,只需查看 Twitter API 文档,您可以在其中立即获得此类问题的答案:) 省去在这里等待别人为您解答的时间!

您会注意到 V1 和 V2 的文档都包含您所描述的属性:

V1 用户对象:

https://developer.twitter.com/en/docs/twitter-api/v1/data-dictionary/object-model/tweet

V2 用户对象:

https://developer.twitter.com/en/docs/twitter-api/data-dictionary/object-model/user