How to get historical tweets with the twitter/tweepy api?

Viewed 98

I am currently trying to do some sentiment analysis on historical tweets from a certain search item, I've read Twitter's/Tweepy's docs but found no answer for obtaining historical tweets(I believe there is a 7 day max look back for the twitter api, but can't find where to implement it in the tweepy docs)

Here's what I have:

#Handler
auth = tweepy.OAuthHandler(c.Twitter_API_key, c.Twitter_API_secretkey)

#Setting access token to know which app we're working with
auth.set_access_token(c.Twitter_AccessToken, c.Twitter_AccessTokenSecret)

#Creating the actual api
api = tweepy.API(auth)

#Search terms
search_term = 'Slap'
tweet_amount = 10
columns = ['Date', 'Tweet', 'Likes', 'ReTweets']
data = []

#Cursor object to search for term
tweets = tweepy.Cursor(api.search_tweets, q=search_term, lang='en', since='2020-101').items(tweet_amount)

for tweet in tweets:
    final_text = tweet.text.replace('RT', '')
    if final_text.startswith('@'):
        position = final_text.index('')
        final_text = final_text[position+2] 
    data.append([tweet.created_at, final_text,tweet.favorite_count,tweet.retweet_count])
df = pd.DataFrame(data, columns=columns)
df
0 Answers
Related