Skip to main content
 首页 » 编程设计

Python Twitter 流 API之仅关注用户

2025年05月04日8qq78292959

我正在尝试仅使用 Python Twitter 获取关注用户的状态图书馆。它适用于“所有人”流:

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 任务。

请您参考如下方法:

其实twython是不支持userstream直播的。参见 here .它的用户组似乎也没有太多事件。