Create Your First Twitter App Using OAuth in Six Simple Steps

This is a simple app that i made two years back.  In the below post i will be sharing simple steps to  create a twitter app using OAuth.



So What is OAUTH ?

WikiPedia has a good explanation on this. We are using OAuth, because twitter moved from Basic Auth to OAuth by mid of 2010 .


Ok so lets create the app in six simple steps. In this twitter app for  dummies, we will try to find the followers of a user.


Step 1:  Follow the link and create a new App by giving  all those blah blah things required. Register your new app .


Step2 :  Go to Twitter Apps Page and find your registered app.  We will be demonstrating a simple app that requires only the access token of a single user . This is provided by twitter  as an example for Single User OAuth Example. So we need the Access token and Access token secret for the user who created the app ( Yea that’s you :-) ). So for  this go to the bottom of the page and there you can see Your Access Token.


Step3 :  Generate your access token and copy it down.  Need to copy Access Token, Access Token Secret. Also note down the Consumer key and Consumer Secret from the same page.


Step 4: Select a twitter api library in any language to make the app. I used tweepy which is a python twitter api library.


Step5: Use tweepy to authenticate using OAuth.


access_key = "replace this with the Access Token you noted down"
acess_secret = "replace this with the Access Token Secret you noted down"
consumer_key = "replace this with the Consumer Key you noted down"
consumer_secret =replace this with the Consumer Secret you noted down"
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(accesskey, accesssecret)

Step 6: Now that we are ready with auth. We will call the api, authenticate and do our stuff.


api = tweepy.API(auth)
 
#print the followers
for follower in tweepy.Cursor(api.followers).items():
print follower.screen_name

Bingo!! Our App is ready

 •  0 comments  •  flag
Share on Twitter
Published on December 31, 2012 13:10
No comments have been added yet.