If you have ever wanted to tweet from one of your python scripts now’s your chance. first things first you will need to install the python twitter api wrapper and all the dependences but that should be pretty straight forward for you.
Next up you will need to get a twitter app develipor acount, to do this all you need to do is head on over to https://dev.twitter.com/ login. Then once logged in click on your icon in the top left corner and select my applications
Then on the next page you will need to click on the create a new application
Just fill in your details on the next page, dont forget to pick a clever name for your app.
after your app has been created you will need to make a note of the ‘Consumer key:’ ‘Consumer secrets:’
These should be a long string of numbers and letter. you should NEVER tell anyone these because these are the keys to your app
When you are using twitter with some kind of scripting/automated scripts your account is more then likey to get banned so its a good idea when testing to use a throw away account and not to use your full time twitter account. Once you get your test account you will need to get the ‘access_token_key’ ‘access_token_secret’ for that account so you can start tweeting using python, to get these keys you will need to run the ‘get_accesss_token.py’ from the python-twitter folder you downloaded.
From this python script you will need to enter your Consumer key and Consumer secrets, then it will spit out a link to open in the browser. Click authorize to give permission to access your twitter account.
Then it will give you a pin number
You need to copy and paste it back into the python script. this will give you your ‘access_token_key’ ‘access_token_secret’ keys
Your first simple twitter app
After all that hard work here is a very simple bit of python code that will allow you to post to twitter. just download this code from my Github put your ‘consumer_key’ ‘consumer_secret’ ‘access_token_key’ ‘access_token_secret’ into this code then run it from terminal like you would any other python script