Skip to content
Advertisement

Timespan for Elevated Access to Historical Twitter Data

I have a developer account as an academic and my profile page on twitter has Elevated on top of it, but when I use Tweepy to access the tweets, it only scrapes tweets from 7 days ago. How can I extend my access up to 2006?

This is my code:

import tweepy
from tweepy import OAuthHandler
import pandas as pd


access_token = '#'
access_token_secret = '#'
API_key = '#'
API_key_secret = '#'

auth = tweepy.OAuthHandler(API_key, API_key_secret)
auth.set_access_token(access_token, access_token_secret)


api = tweepy.API(auth, wait_on_rate_limit=True)

tweets = []

count = 1


for tweet in tweepy.Cursor(api.search_tweets, q= "#SEARCHQUERY", count=5000).items(50000):
    
    print(count)
    count += 1

    try: 
        data = [tweet.created_at, tweet.id, tweet.text,
tweet.user._json['screen_name'], tweet.user._json['name'], tweet.user._json['created_at'], tweet.entities['urls']]
        data = tuple(data)
        tweets.append(data)
        

    except tweepy.TweepError as e:
        print(e.reason)
        continue

    except StopIteration:
        break

df = pd.DataFrame(tweets, columns = ['created_at','tweet_id', 'tweet_text', 'screen_name', 'name', 'account_creation_date', 'urls'])

df.to_csv(path_or_buf = 'local address/file.csv', index=False)

Advertisement

Answer

The Search All endpoint is available in Twitter API v2, which is represented by the tweepy.Client object (you are using tweepy.api).

The most important thing is that you require Academic research access from Twitter. Elevated access grants addition request volume, and access to the v1.1 APIs on top of v2 (Essential) access, but you will need an account and Project with Academic access to call the endpoint. There’s a process to apply for that in the Twitter Developer Portal.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement