Any ways to retrive tweets based on hashtag for a time frame more than a year?

Im looking for ways to retrieve tweets from Twitter which contains certain hashtags. I tried to use the official API and tweepy package in Python but even with academic access I was only able to retrieve tweets which are 7 days old. I want to retrieve tweets from 2019 till 2020 but Im not able to do so with tweepy.

I tried the following packages GetOldTweet3, twint but none of them seem to work due to some changes Twitter made last year.

Can someone suggest a way to get old tweets with certain hashtags. Thanks in advance for any help or suggestion provided.

Upvotes: 0

Views: 1014

Answers (1)

anon
anon

Reputation:

If you have academic access, you are able to use the full archive search API available in the Twitter API v2. Tweepy has support for this via the tweepy.Client class. There's a full tutorial on DEV, but the code will be something like this:

import tweepy

client = tweepy.Client(bearer_token='REPLACE_ME')

# Replace with your own search query
query = 'from:andypiper -is:retweet'

tweets = client.search_all_tweets(query=query, tweet_fields=['context_annotations', 'created_at'], max_results=100)

for tweet in tweets.data:
    print(tweet.text)
    if len(tweet.context_annotations) > 0:
        print(tweet.context_annotations)

You can use search query parameters to specify the date range.

Upvotes: 1

Related Questions