How to Tweet From Python

Step one

Download and install twython, using pip. I’m using python 3 so I typed the command

sudo pip3 install twython

 

 

Step 2

Go to apps.twitter.com and create an account using your Twitter username and password.

 

Step 3

Click ‘Create New App’

Step 4

Fill in the mandatory fields and click next, if you don’t have a website just pop in a placeholder.

 

Step 5

Once your app is created you will now will be brought through to a new page, click ‘Key and Access Tokens’.

 

Step 6

Take note of the Consumer Key (API Key) and Consumer Secret (API Secret)

 

Step 7

You will need to create an access token.

 

 

Step 8

You should now see your access tokens, take note of these also.

 

Step 9

Open up your favorite text editor, I’m using Idle, and enter the following:

from twython import Twython

 

APP_KEY = ‘YOUR_KEY_GOES_HERE’
APP_SECRET = ‘YOUR_SECRET_GOES_HERE’
OAUTH_TOKEN = ‘YOUR_TOKEN_GOES_HERE’
OAUTH_TOKEN_SECRET = ‘YOUR_TOKEN_SECRET_GOES_HERE’

 

twitter = Twython(APP_KEY, APP_SECRET, OAUTH_TOKEN, OAUTH_TOKEN_SECRET)
twitter.update_status(status=’this is a test tweet from a python script!’)

 

Step 7

Now run your script, if using Idle, you can do this by pressing F5.

 

Step 8

Check Twitter to make sure your tweet has sent.

Leave a Reply

Your email address will not be published. Required fields are marked *