簡體   English   中英

tweepy的Twitter時間軸流

[英]twitter timeline streaming with 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')

如果您看一下文檔,它會顯示:

Tweepy的StreamListener的on_data方法可以方便地將數據從狀態傳遞到on_status方法。

您看到的數字是Tweets的對象ID。 您將需要執行以下操作:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM