问题
I am trying to get older tweet data (approximately 2 months old) using tweepy in Python. I tried since and until parameters but no success. Has anyone got a work around in tweepy or some other API.
for id,tweet in enumerate (tweepy.Cursor(api.search, q='SpecificWord', since="2016-04-26", until="2016-04-28", lang="en", include_retweets=False ).items(200)):
#Write a row to the csv file
CSVW.writerow([tweet.created_at, tweet.retweet_count, tweet.text.encode('utf-8')])
回答1:
This is not possible. The docs on the Twitter API are very clear:
The Twitter Search API searches against a sampling of recent Tweets published in the past 7 days.
There is no way to search back further than that.
回答2:
There are 2 ways to get older tweets.
You get the forked version of Tweepy, which supports multiple authentication handlers. Here is an instruction on how to use it (unfortunately only with Python 2.7). Or you use this ratetime limiter for Tweepy. But with the Twitter API the oldest data you can get is about 7 days I think.
The other way is to use GetOldTweets-python, it also works with Python 3. Here is an example on how to use it.
First Install lxml (Version 3.5) & pyquery Version 1.2.10):
pip3 install lxml==3.5.0
pip3 install pyquery==1.2.10
Then download GetOldTweets-python and copy the folder got3 into you site packages folder and run Python.
import got3
max_tweets = 3
tweetCriteria = got3.manager.TweetCriteria().setUntil("2016-01-31").setQuerySearch("bitcoin").setMaxTweets(max_tweets)
for i in range(max_tweets):
tweet = got3.manager.TweetManager.getTweets(tweetCriteria)[i]
print(tweet.id)
print(tweet.username)
print(tweet.text)
print(tweet.date)
Now you are getting Tweets from 2016!
693584301917655041
bitcoinfirehose
Teenagers are using untraceable currency Bitcoin to buy dangerous drugs online http://ift.tt/20eIDwU #reddit #bitcoin
2016-01-31 00:59:18
693584300265070593
bitcoinfirehose
Hey guys I've seen a need to cashout to Visa. So I created a site to get moneypak codes via Bitcoin ! Please come check it out! …
2016-01-31 00:59:18
693584286210002944
b1eedr
Bitcoin 2.0: Fantasy Or Inevitability? https://www.cryptocoinsnews.com/bitcoin-2-0-fantasy-or-inevitability/ @CryptoCoinsNews
2016-01-31 00:59:14
来源:https://stackoverflow.com/questions/37017903/older-tweets-tweepy-using-python