Compiled from a couple of pages, and some trial and error.
You will need:
- Windows (any version, afaik)
- A twitter account where you have confirmed your email address
- Python (2.7)
Step 1: Get your Twitter Api key
You will need to be a twitter user to get an api key. You will need an api key for some of the things you'll do later. You don't absolutely need to do this step right now but it's probably eaiser.
This explains the process pretty clearly When you're filling out the form, it doesn't matter what you put in the fields for "app name" and "website", etc.
You will also need the access token, so click on the button at the bottom of the page to get that.
Also, go into your settings (there should be a tab at the top of the page), scroll down to 'Application Type' and choose 'Read and Write'. This will mean you can update your twitter status, and things like that. (Then, obviously, scroll down and click on 'Update this Twitter application's settings')
If you'd already created your access token before doing this, you will need to re-do that to update it with the new permissions. Click 'Recreate my access token'.
Step 2: Download the python wrapper for the twitter api and its dependencies
Open up a Command Prompt
( Start->Accessories->Command Prompt )
Type: cd c:\Python27\scripts
Type: easy_install simplejson
(wait. read what's on the screen - hopefully not an error)
Type: easy_install httplib2
(wait, etc)
Type: easy_install oauth2
(wait, etc)
Type: easy_install twitter
(wait, etc - and if that doesn't work, try: easy_install pip
then: pip install twitter )
You should now be good to go.
Step 2: Setting up the twitter api wrapper in python
Open up a Python shell window. You should get this if you go :
Start -> Programs -> Python27 -> IDLE (Python Gui)
It should look like this:
Type: import twitter
(nothing happens)
Type: api = twitter.Api()
(nothing happens)
We're now referring to the official documentation here.
Type:
api = twitter.Api(consumer_key='consumer_key',
consumer_secret='consumer_secret',
access_token_key='access_token',
access_token_secret='access_token_secret')
- Except that where it says 'consumer_secret', 'access_token', etc (everything with the single quote marks), write in the Consumer Key / Consumer Secret / etc that you got in Step 1. Keep the quote marks.
Also, you don't need to press Enter between these lines, but it doesn't matter if you do.
To check that that has worked, type:
print api.VerifyCredentials()
When you press Enter you should get a bunch of text (hopefully not any errors).
What would be a good idea right now is to save this script, so that you don't have to go back and remember/retype all of that next time you want to work.
(In the Python Shell window, File->Save)
Step 4: Try a few things out
(These are from the Google Code page):
allstatuses = api.GetPublicTimeline()
print [s.user.name for s in statuses]
statuses = api.GetUserTimeline("user")
(The username is text, so must be in quote marks)
friends = api.GetFriends("user")
print [f.name for f in friends]
(For list of people the user is "following")
and... away you go. full documentation here.
