Tweepy是应该使用pip安装的库之一。现在,为了授权我们的应用代表我们访问Twitter,我们需要使用OAuth接口。Tweepy提供了方便的Cursor接口来迭代不同类型的对象。Twitter允许最多提取3200条推文。
这些都是在收到用户推文之前必须使用的先决条件。
import tweepy
# Fill the X's with the credentials obtained by # following the above mentioned procedure. consumer_key = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" consumer_secret = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"access_key = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"access_secret = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
# Function to extract tweets def get_tweets(username):
# Authorization to consumer key and consumer secret
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
# Access to user's access key and access secret
auth.set_access_token(access_key, access_secret)
# Calling api
api = tweepy.API(auth)
22.0798
1
4
关注作者
收藏
发表评论
暂无数据

