This sample code shows you how you might build a demo web app with Python and Flask and exemplifies some of the features and functionality available with the Twitter API v2 and Tweet Annotations.
-
In the root directory, rename
credentials.yaml.template
tocredentials.yaml
and insert your Twitter App credentials. Note that you must use the credentials belonging to a Twitter Developer App with access to the Twitter API v2. -
Don't forget to add
credentials.yaml
to your.gitignore
file to avoid compromising your App credentials.
Follow these steps to run the web app on your local machine:
- From the root directory in the command line type:
export FLASK_ENV=development
. (On Windows, useset
instead ofexport
.) - Then type
flask run
. - The web app is now running on your local host (usually something like
http://127.0.0.1:5000/
). - Further information on configuring your Flask app can be found here.
This web app illustrates the following functionality:
- Get topics of interest for a profile (including top Tweet Annotations associated with a profile's Tweets and top most used emojis by this profile).
- Get topics of interest for a profile's followers. Same functionality as above, but for a user profile's follower base.
- For a given topic, get a list of users who recently Tweeted about this topic.
- For a given topic, get resonance metrics (including number of Tweets sent within the past 7 days, and aggregate engagement metrics, such as retweets, quote Tweets, likes, and replies).