Not logged in
Talk
Contributions
Create account
Log in
Navigation
Main page
About
People
Publications
Teaching
Resources
Research Blog
Wiki Functions
Recent changes
Help
Licensing
Page
Discussion
Edit
View history
Editing
Intro to Programming and Data Science (Spring 2020)/Day 8 Coding Challenges
(section)
From CommunityData
Jump to:
navigation
,
search
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== Prerequisite == To get this code to work, you ''must'' have registered with Twitter as a developer by following the [[Intro_to_Programming_and_Data_Science_(Spring_2020)/Twitter authentication setup|Twitter authentication setup instructions]]. ===Download the Twitter API project=== We will be building on material created for the [Community Data Science Workshops]. * Download the following zip file: https://github.com/CommunityDataScienceCollective/twitter-cdsw/archive/master.zip * Extract the zip folder into a new folder on your Desktop. ===Enter your API information=== * Start Juypter notebook and navigate to the folder you just created on your desktop. * Double click to open the file "twitter_authentication.py". This is a python file, meaning it contains python code, but it is not a notebook. * You will see four lines that include four variables in ALL CAPITALS. At the moment, all of the strings say CHANGE_ME. * Go find the four keys, tokens, and secrets you created when you followed the [[Intro_to_Programming_and_Data_Science_(Spring_2020)/Twitter authentication setup|Twitter authentication setup]]. Change every string that says CHANGE_ME into a string that includes the key, token, or secret you downloaded. Remember that since these are strings, we need to include quotations marks around them. Also make sure that you match up the right keys and tokens with the right variables. Once you have done this, your example programs are set up to use the Twitter API! ===Test the Twitter API code=== Open the notebook "ex0_print_a_tweet.py" in jupyter. Execute all of the cells. You should see the text of 100 tweets in the second to last cell. If you see an error, you probably have a problem with the API information you entered in the previous step. === Making your own notebooks === we are using [http://www.tweepy.org/ tweepy], a python library that simplifies accessing the Twitter API. You will do the exercises below in your own notebook, which you will create. In every notebook you make, put the following python code in the first cell: import tweepy from twitter_authentication import CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET) auth.set_access_token(ACCESS_TOKEN, ACCESS_TOKEN_SECRET) api = tweepy.API(auth) This will enable your authenticated Twitter API calls via the variable <code>api</code>
Summary:
Please note that all contributions to CommunityData are considered to be released under the Attribution-Share Alike 3.0 Unported (see
CommunityData:Copyrights
for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource.
Do not submit copyrighted work without permission!
To protect the wiki against automated edit spam, we kindly ask you to solve the following CAPTCHA:
Cancel
Editing help
(opens in new window)
Tools
What links here
Related changes
Special pages
Page information