2011-09-13 120 views
2

我試圖獲取僅使用Python Twitter庫的跟隨用戶的狀態。它適用於'每個人'流:Python Twitter流媒體API - 僅限用戶

from twitter.stream import TwitterStream 
from twitter.oauth import OAuth 
from twitter.util import printNicely 

stream = TwitterStream(
    auth=OAuth(
       acc_key, acc_secret, 
       con_key, con_secret), 
       domain="userstream.twitter.com", 
       api_version='1', 
       secure=True) 
print stream.statuses.sample() 
tweet_iter = stream.statuses.sample() 
for tweet in tweet_iter: 
    if tweet.get('text'): 
     printNicely(tweet['text']) 

但我想限制輸出給我只遵循的用戶。據我可以告訴從文檔,sample()給了我一切,但我不知道是否有filter()方法。我應該使用不同的圖書館嗎?我一直在使用Tweepy進行非流式Twitter任務。

回答

0

我推薦twython作爲Python Twitter庫。它定期維護,考慮到Twitter更改API的頻率,這是一個有用的屬性。

編輯:請參閱tweetstream,瞭解簡單的流式API實現,以實現過濾功能。

+0

@urschrei你是對的。這兩個庫本身都不支持'/ filter'方法。 – sye

0

實際上,twython不支持userstream直播流。見here。在用戶羣中似乎也沒有太多活動。

+0

@sye這應該是你的答案的評論 – urschrei