Reputation: 387
I tried the following codes:
class MyListener(StreamListener):
def on_data(self, data):
print(data)
return True
listener = MyListener()
auth = OAuthHandler(config.API_KEY, config.API_SECRET)
auth.set_access_token(config.ACCESS_TOKEN, config.ACCESS_TOKEN_SECRET)
stream = Stream(auth, listener)
stream.filter(follow=['<user_id>']) # assume this user is a celebrity
What I got when running this code, is many spam-tweets or retweets by other users. (assume this <user id>
is a celebrity, who has millions of followers. The followers are sharing the tweets all the time)
But I want to stream the original tweets published only
by this specific <user id>
. How can I implement this? Thanks in advance.
Upvotes: 6
Views: 1459
Reputation: 3148
The official documentation says that using the follow
parameter you get :
So you just have to skip tweets not posted by the specified user :
def on_status(self, status):
if status.user.id_str != '<user_id>':
return
print(status.text)
Upvotes: 9