Python Twitter API-如何通过用户获取实时推文
有没有一种通过Twitter句柄或Twitter ID获取实时推文的方法 我尝试过使用,但只能通过关键字过滤推文:Python Twitter API-如何通过用户获取实时推文,python,twitter,tweepy,Python,Twitter,Tweepy,有没有一种通过Twitter句柄或Twitter ID获取实时推文的方法 我尝试过使用,但只能通过关键字过滤推文: 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
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用户名下拉推文?您应该可以这样传递关键字:
stream.filter(follow=['user_id'])
它接收一个用户ID列表
从文档中,应返回:
- 用户创建的推文
- 用户转发的推文
- 回复用户创建的任何推文
- 用户创建的任何推文的转发
- 手动回复,不按回复按钮创建(例如“@twitterapi I agree”)
- 提及用户的推文(例如,“Hello@twitterapi!”)
- 无需按下Retweet按钮即可手动创建Retweet(例如,“RT@twitterapi API非常棒”)
- 受保护用户的推文
您可以指定
track
和follow
两个值,它将生成带有输入关键字的tweet或由输入用户创建的tweet 嘿,福吉,有没有办法利用受保护的用户?如何只获取原始用户创建的推文,而不获取其他内容(转发等)?