HackNights Python the Twitter API
Check if you have python installed
- Go to your terminal emulator
- Type
python --version
andpip --version
- If it doens't work you may need to install it
The easiest is downloading the packages from Python website then Setuptools
Install the library TwitterAPI there are many others if you want to have a try.
On your command line tool / terminal type
pip install TwitterAPI
In order to access Twitter through our Python scripts it's necessary to request access and adquire four different keys.
- You need a Twitter account www.twitter.com
- Create a new application https://apps.twitter.com/app/new at the Website field you can put any website starting with http and you can let the field Callback URL empty
- Then go to https://apps.twitter.com/
- Click on your App then click in the tab Keys and Access Tokens
- In the bottom of the page click on generate Access Token, copy the follow keys
consumer_key = ""
consumer_secret = ""
access_token_key = ""
access_token_secret = ""
if you want to explore the API through the API console https://dev.twitter.com/rest/tools/console
-
Download the zip file from this repo
-
Edit the file
keys.py
and insert your keys between quotes""
for each variable -
Edit the file
twitter_0_Simple_Post.py
and edit the message you want to tweet. -
To run your script go to your command line tool /terminal
-
Go to the folder where are all the
.py
files are then type
python twitter_0_Simple_Post.py
you may get a number as output, if it is 200 Sucess otherwise have a look at the error response codes from twitter
- Try the other scripts
.py
following these instructions