我想用 python 和 tweepy 流式传输我自己的 Twitter 时间线,并使用下面的代码,但它只是打印一些数字,而我不打印我的时间线 twitts。你能帮我吗?
import tweepy
from tweepy import Stream
from tweepy.streaming import StreamListener
consumer_key = 'abc'
consumer_secret = 'abc'
access_token = 'abc'
access_secret = 'abc'
auth = OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_secret)
api = tweepy.API(auth)
class listener(StreamListener):
def on_data(self, data):
print (data)
return True
def on_error(self, status):
print (status)
twitterStream = Stream(auth, listener())
twitterStream.userstream(encoding='utf8')
最佳答案
如果您采取 look at the documentation它说:
The
on_data
method of Tweepy’s StreamListener conveniently passes data from statuses to theon_status
method.
您看到的数字是推文的对象 ID。您需要执行以下操作:
def on_status(self, status):
print(status.text)
关于python - 使用 tweepy 流式传输 Twitter 时间线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45089988/