sem*_*lex 4 python twitter tweepy
有没有办法Tweepy通过Twitter手柄或Twitter ID 提取实时推文?
我尝试过使用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'])
Run Code Online (Sandbox Code Playgroud)
无论如何我可以通过Twitter用户名下拉推文吗?
你应该能够follow像这样传递关键字:
stream.filter(follow=['user_id'])
Run Code Online (Sandbox Code Playgroud)
它接收用户ID列表.
从API文档中,这应该返回:
它没有返回:
注意
您可以指定两者track和follow值,它将生成带有输入关键字的推文或输入用户创建的推文.
| 归档时间: |
|
| 查看次数: |
4641 次 |
| 最近记录: |