How to Download Tweets
Twitter is an excellent source for information. Some recent research has started to analyze tweets from consumers, investors, executives, and companies. If you know the twitter handler, you can easily download its most recent 3,200 tweets. As an example, here are the Tweets by SP500 CEO/CFO/Chairman that I downloaded in October 2015 -- Tweets. You need to call Twitter's REST API, which provides programmatic access to read and write Twitter data. See here for details.
Detailed Procedures
There are three steps. First, install Python as the code is written in Python. Second, you will need Twitter API credential (Twitter uses OAuth to provide authorized access to its API). Third, format the twitter handlers you want to download.
Step 1: install Python:
a. Install the latest Python 2.* (currently 2.7.13) Note: I have tried both Python 2 and Python 3 (works with 3.6.2). Both work.
b. Install Conda, a package manager and an environment manager application. You only need the simple version (Miniconda). You can download it here.
c. Create a new environment with Conda, activate it and install packages. Run the following commands under command line.
conda create -n tweet python
activate tweet
conda install tweepy
Note: You can use any name for the environment, I use tweet. Tweepy is the Python module this code needs (last verified with Tweepy 3.8).
Step 2: Obtain Twitter API credentials, including Consumer Key, Consumer Secret, Access Key and Access Secret.
a. Register a twitter account.
b. Login on https://apps.twitter.com/ and create an app (use any name).
c. Go to Keys and Access Tokens , you will have the Consumer Key and Consumer Secret.
d. Under Token Action, click the button Generate My Access Token and Token Secret, you will see the Access Token and Access Token Secret.
e. Use these four credentials in the python program download_tweet.py (you will need to change the extension of the downloaded file from .txt to .py).
Step 3: Format your twitter handlers file
a. Use a plain text file for the twitter handlers you want to download tweets. Include only one twitter handler per line. Save the file as handler_list.txt.
b. Put both download_tweet.py and handler_list.txt in the same directory.
c. Navigate to the directory with the python code under command line.
d. Run the Python code.
python download_tweet.py
Note: Before you run the code, make sure the conda environment is activated. If it's not, activate it by running this under command line:
activate tweet
Twitter is an excellent source for information. Some recent research has started to analyze tweets from consumers, investors, executives, and companies. If you know the twitter handler, you can easily download its most recent 3,200 tweets. As an example, here are the Tweets by SP500 CEO/CFO/Chairman that I downloaded in October 2015 -- Tweets. You need to call Twitter's REST API, which provides programmatic access to read and write Twitter data. See here for details.
Detailed Procedures
There are three steps. First, install Python as the code is written in Python. Second, you will need Twitter API credential (Twitter uses OAuth to provide authorized access to its API). Third, format the twitter handlers you want to download.
Step 1: install Python:
a. Install the latest Python 2.* (currently 2.7.13) Note: I have tried both Python 2 and Python 3 (works with 3.6.2). Both work.
b. Install Conda, a package manager and an environment manager application. You only need the simple version (Miniconda). You can download it here.
c. Create a new environment with Conda, activate it and install packages. Run the following commands under command line.
conda create -n tweet python
activate tweet
conda install tweepy
Note: You can use any name for the environment, I use tweet. Tweepy is the Python module this code needs (last verified with Tweepy 3.8).
Step 2: Obtain Twitter API credentials, including Consumer Key, Consumer Secret, Access Key and Access Secret.
a. Register a twitter account.
b. Login on https://apps.twitter.com/ and create an app (use any name).
c. Go to Keys and Access Tokens , you will have the Consumer Key and Consumer Secret.
d. Under Token Action, click the button Generate My Access Token and Token Secret, you will see the Access Token and Access Token Secret.
e. Use these four credentials in the python program download_tweet.py (you will need to change the extension of the downloaded file from .txt to .py).
Step 3: Format your twitter handlers file
a. Use a plain text file for the twitter handlers you want to download tweets. Include only one twitter handler per line. Save the file as handler_list.txt.
b. Put both download_tweet.py and handler_list.txt in the same directory.
c. Navigate to the directory with the python code under command line.
d. Run the Python code.
python download_tweet.py
Note: Before you run the code, make sure the conda environment is activated. If it's not, activate it by running this under command line:
activate tweet