Tweeting from python

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

Twitter Developers - Chromium_005

Then on the next page you will need to click on the create a new application

My applications | Twitter Developers - Chromium_006

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:’

PY-Bot | Twitter Developers - Chromium_011

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.

facelessloser@facelessloser-X501A: ~-Downloads-python-twitter-master_012

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.

Twitter - Authorize an application - Chromium_008

Then it will give you a pin number

Twitter - Authorize an application - Chromium_009

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

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s