【发布时间】:2016-06-25 14:28:04
【问题描述】:
有没有办法通过 Twitter 句柄或 Twitter ID 使用 Tweepy 拉取实时推文?
我尝试过使用Twitter Streaming API,但只能获得按关键字过滤的推文:
import tweepy
import json
# Import the necessary methods from tweepy library
from tweepy.streaming import StreamListener
from tweepy import OAuthHandler
from tweepy import Stream
# Variables that contains the user credentials to access Twitter API
access_token = "INSERT ACCESS TOKEN"
access_token_secret = "INSERT ACCESS TOKEN SECRET"
consumer_key = "INSERT CONSUMER KEY"
consumer_secret = "INSERT CONSUMER SECRET"
# This is a basic listener that just prints received tweets to stdout.
class StdOutListener(StreamListener):
def on_data(self, data):
print data
return True
def on_error(self, status):
print status
if __name__ == '__main__':
# This handles Twitter authentication and connection to Twitter Streaming API
l = StdOutListener()
auth = OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
stream = Stream(auth, l)
stream.filter(track=['european central bank'])
有没有我可以通过 Twitter 用户名下拉推文?
【问题讨论】: