I am new to the twitter api and I like to create a app that subscribe a stream from a user
using the tweepy, here is the snippet of the code
def on_data(self, data):
print(data)
return True
def on_status(self, status):
print(status.text)
return True
def on_error(self, status):
print(status)
if name == ‘main’:
l = StdOutListener()
auth = OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
#api.create_friendship(user_id)
stream = Stream(auth, l)
#stream.filter(track=["basketball"])
stream.filter(follow=["127955543552812335"])
where 127955543552812335 is the user_id from my twitter username (you can find this user id from the find twitter id website
however, I did not see the message flow when I twitt from my account
anything wrong I did? (I verified that I set the oauth correctly)
consumer_key,
consumer_secret,
access_token
access_token_secret
I can see the message flow for the track filter as following:
stream.filter(track=[“basketball”])
but I did not see the message I twitted.
any ideas?
appreciated!
1 Like
follow should stream the tweets listed here: Standard stream parameters | Docs | Twitter Developer Platform
The forum formatting mangled the code block, so i can’t see what may be wrong but here’s another example that should work:
from tweepy import StreamListener
from tweepy import Stream
import tweepy
auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
auth.set_access_token(ACCESS_KEY, ACCESS_SECRET)
api = tweepy.API(auth)
class StdOutListener(StreamListener):
def on_data(self, data):
# process stream data here
print(data)
def on_error(self, status):
print(status)
if __name__ == '__main__':
listener = StdOutListener()
twitterStream = Stream(auth, listener)
twitterStream.filter(follow=["127955543552812335"])
2 Likes
system
Closed
#3
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.