简体   繁体   English

如何通过 tweepy stream 指定用户 ID?

[英]How to stream a specific user_id by tweepy?

I'm trying to reach out an event to recognize whenever specific user tweets, so im using stream.filter in tweepy, just like我试图联系一个事件来识别特定用户的推文,所以我在 tweepy 中使用 stream.filter ,就像

class IDPrinter(tweepy.StreamingClient):

def on_tweet(self, tweet):
    print(tweet)
printer = IDPrinter("bearer")
printer.sample(expansions=['author_id'],user_fields=['1234']) #consider 1234 user_id to follow

but Stream encountered HTTP error: 400 ,what am i missing?但是Stream encountered HTTP error: 400 ,我错过了什么? im having api v2 and allowing OAuth v2 as well我有 api v2 并允许 OAuth v2

To be able to filter streaming data you need to give rules initially.为了能够过滤流数据,您首先需要给出规则。 So if you want to stream tweets of user with id 1234 you need give a rule for that, then when you start streaming, tweets that satisfy your rule will be retrieved.因此,如果您想要 ZF7B44CFFAFD5C52223D5498196C8A2E7BZ 用户的 id 为1234的推文,您需要为此指定一个规则,然后当您开始流式传输时,将检索满足您的规则的推文。

For more information about adding rules on tweepy: StreamRule有关在 tweepy 上添加规则的更多信息: StreamRule

For more about Twitter Api v2 Filtered Stream: How to build a rule有关 Twitter Api v2 过滤的 Stream 的更多信息: 如何构建规则

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM