Skip to content
Advertisement

How do I get username on tweepy streamer?

I am using Tweepy.StreamingClient to get some tweets but I am not able to get the username even if I add the filters. I am using the v.4.10.1 of Tweepy

from tweepy import StreamingClient

class TweetStreamerV2(StreamingClient):

   def on_tweet(self, tweet):
      # here I tried the following and nothing is returned 
      print(tweet.inlcudes)
      print(tweet.user)

streamer = TweetStreamerV2(bearer_token)

# add new rules
rule = StreamRule(value="xxx")
streamer.add_rules(rule)


# add filters
streamer.filter(expansions="author_id", tweet_fields="created_at", user_fields="username")

Advertisement

Answer

Okay I figure it out!

I’m using on_tweet that only bring the class Tweet. Tweepy on_tweet

Instead I should use on_data that bring all info needed. Tweepy on_data

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement