Friday, March 26, 2010

Twitter OAuth Login - Part 2

The part 1 of this post can be checked here

1. First Step : Get a Twitter Account


If you already have a twitter account then you can ignore it else you need to create one at twitter.

2. Second Step : Register your application with Twitter

a. Log in to Twitter.
b. On the top menu, click 'settings'
c. On the settings page, you will see another menu, click 'connections.'
d. On the right hand, you will see a heading 'Developers' with a link to manage your application, click it.

e. You will be redirected to a page with a link to 'register new application,' click it.

f. Fill in the application registration form, it asks for some general information about your website like name and website url. Some important fields you need to fill in correctly are,
  • Call back URL - That's the page user will be redirected to once he will provide twitter his authentication details. This url will eventually be talking back to Twitter in order to get the access token for the user.
  • Application Type : Select 'browser.' 'Client' in other words desktop applications are out of the scope of this document.
  • Default Access Type : If you want to allow user to update his Twitter status right from your application then select 'Read & Write' else just 'Read.'
  • Use Twitter for login : Select it.



g. Once the form has been filled, submit it. If the application has been registered successfully, it will start appearing on Manage Applications page.

3. Third Step : Integrate it into your website

In order to integrate Twitter, you need a Twitter library with OAuth support. You may decide to write everything from scratch but hopefully you wouldn't want to reinvent the wheel. The one that I used is written by 'Elliot Haughin' and you can download it from here : http://www.haughin.com/code/twitter/

He developed it mainly for codeigniter framework but it would work just fine if used otherwise, you may just have to replace some codeigniter keywords. If you want to use a non codeigniter library then check out this one : http://github.com/abraham/twitteroauth

I would be using Elliot's library in rest of the article.

The next post will be the last in the series and would be discussing the code we need to write.

1. Part 1
2. Part 2
3. Part 3

1 comment: