Starter code used for live demo of integrating the Twitter API and Python for EECS 398 Fall 2018 at University of Michigan, Ann Arbor. Last semester's demo on graphing hashtag usage can be found here
$ pip3 install twarc
-
created specifically to pull data from Twitter
-
handles authentication in one line
-
not very well-documented, but it has the reply-searching functionality we're looking for
pip3 install anytree
-
simple and easy to use
-
gives node functionality to any user-defined class
-
builds AND renders trees
-
you want to keep your API keys secret, which is why they are placed in a separate file from your program.
-
if you choose to put your project on GitHub, DO NOT commit
secret.py
Go to https://apps.twitter.com
-
sign into Twitter, then click "Create New App" in the upper right
-
fill out the name, description, and website for your application. Check the "Developer Agreement" box and finish creating your app!
-
under the name of your application, find and click the "Keys and Access Tokens" tab
-
located under Application Settings
-
copy and paste these keys into
secret.py
-
scroll down and click "Authorize my Application"
-
located under "Your Access Token"
-
copy and paste these keys into
secret.py
-
from twarc import Twarc
-
from anytree import NodeMixin, RenderTree
-
from secret import *
-
check out "Using as a Library" in the twarc README
-
use keys/tokens from
secret.py
to create the session
- ask the user (you) for a Tweet ID
-
use your twarc session for this
-
the Tweet will be represented as a large dictionary
-
we have to be resourceful here - there's no documentation on twarc's reply functionality, but we can look at twarc's test file on GitHub to figure out how to use it
-
"take the recursive leap of faith!"
- use anytree's
RenderTree
functionality