python - 使用 tweepy 流式传输 Twitter 时间线

标签 python twitter tweepy

我想用 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 the on_status method.

您看到的数字是推文的对象 ID。您需要执行以下操作:

def on_status(self, status):
    print(status.text)

关于python - 使用 tweepy 流式传输 Twitter 时间线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45089988/

相关文章:

python - 解决错误 104 和 Twitter 速率限制

python - 如何使用 shell = true 通过 Python subprocess.Popen() 将 SIGINT 传递给子进程

python - 需要理解python中单行两个lambda的含义

python - 为什么对未 pickle 的 cifar10 数据集进行 pickle 会产生不同的大小?

twitter - 为什么这个错误 ' - Read-only application cannot POST '

ios - 访问用户twitter账号IOS

ios - 如何在 iOS 中使用 Twitter/社交框架获取关注者和关注者

python - 使用 Tweepy 抓取抓取坐标并绘制它们

python - 访问json中的随机命名键

python - 获取 tweepy 用户组的关注者和关注者列表