使用Python中的Twitter API搜索过去24小时内特定帐户的推文,可以通过以下步骤实现:
pip install tweepy
import tweepy
import datetime
consumer_key = 'YOUR_CONSUMER_KEY'
consumer_secret = 'YOUR_CONSUMER_SECRET'
access_token = 'YOUR_ACCESS_TOKEN'
access_token_secret = 'YOUR_ACCESS_TOKEN_SECRET'
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
请将YOUR_CONSUMER_KEY、YOUR_CONSUMER_SECRET、YOUR_ACCESS_TOKEN和YOUR_ACCESS_TOKEN_SECRET替换为你在Twitter开发者平台上获取的实际值。
api = tweepy.API(auth)
account = 'SPECIFIC_ACCOUNT'
search_days = 1
now = datetime.datetime.now()
search_date = now - datetime.timedelta(days=search_days)
请将SPECIFIC_ACCOUNT替换为你要搜索的特定帐户的Twitter用户名。
tweets = tweepy.Cursor(api.user_timeline, id=account, since=search_date).items()
for tweet in tweets:
print(tweet.text)
这将打印出过去24小时内特定帐户的所有推文。
领取专属 10元无门槛券
手把手带您无忧上云