I have a list of tweet ids for which I would like to download their text content. Is there any easy solution to do this, preferably through a Python script? I had a look at other libraries like Tweepy and things don't appear to work so simple, and downloading them manually is out of the question since my list is very long.
Today, Twitter IDs are unique 64-bit unsigned integers, which are based on time, instead of being sequential. The full ID is composed of a timestamp, a worker number, and a sequence number.
Navigate to your app dashboard. Select the app you've enabled with the Tweets and users preview, then click Details. Select the Keys and tokens tab. In the Consumer API Keys section, copy the values for API Key into consumer_key and API Secret Key into consumer_secret .
Both Historical PowerTrack and Full-Archive Search provide access to any publicly available Tweet, starting with the first Tweet from March 2006. Deciding which product better suits your use case can be key in getting the data you want when you need it.
GET statuses/show/:id Returns a single Tweet, specified by the id parameter. The Tweet's author will also be embedded within the Tweet.
You can access specific tweets by their id with the statuses/show/:id
API route. Most Python Twitter libraries follow the exact same patterns, or offer 'friendly' names for the methods.
For example, Twython offers several show_*
methods, including Twython.show_status()
that lets you load specific tweets:
CONSUMER_KEY = "<consumer key>" CONSUMER_SECRET = "<consumer secret>" OAUTH_TOKEN = "<application key>" OAUTH_TOKEN_SECRET = "<application secret" twitter = Twython( CONSUMER_KEY, CONSUMER_SECRET, OAUTH_TOKEN, OAUTH_TOKEN_SECRET) tweet = twitter.show_status(id=id_of_tweet) print(tweet['text'])
and the returned dictionary follows the Tweet object definition given by the API.
The tweepy
library uses tweepy.get_status()
:
auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET) auth.set_access_token(OAUTH_TOKEN, OAUTH_TOKEN_SECRET) api = tweepy.API(auth) tweet = api.get_status(id_of_tweet) print(tweet.text)
where it returns a slightly richer object, but the attributes on it again reflect the published API.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With