首先,Twitter API不允许按时间搜索。琐碎地,您可以做的是获取推文,然后在Python中查看它们的时间戳,但这效率很低。
您可以通过以下代码段来实现。
consumerKey = "CONSUMER_KEY"consumerSecret = "CONSUMER_SECRET"accessToken = "ACCESS_TOKEN"accessTokenSecret = "ACCESS_TOKEN_SECRET"auth = tweepy.OAuthHandler(consumerKey, consumerSecret)auth.set_access_token(accessToken, accessTokenSecret)api = tweepy.API(auth)username = sys.argv[1]startDate = datetime.datetime(2011, 6, 1, 0, 0, 0)endDate = datetime.datetime(2012, 1, 1, 0, 0, 0)tweets = []tmpTweets = api.user_timeline(username)for tweet in tmpTweets: if tweet.created_at < endDate and tweet.created_at > startDate: tweets.append(tweet)while (tmpTweets[-1].created_at > startDate): tmpTweets = api.user_timeline(username, max_id = tmpTweets[-1].id) for tweet in tmpTweets: if tweet.created_at < endDate and tweet.created_at > startDate: tweets.append(tweet)
虽然效率很低。它有效,可以帮助我创建自己的机器人。



