How to Authenticate a Twitter User For Twitter Using OAuth API V1.1

Introduction

 
On 11th June 2013, Twitter officially closed its V1.0 API and has now migrated to the v1.1 API. This means that we need to authenticate users before being able to display Tweets from a user's profile, even it is a public profile. Yes, you read it correctly; even if the user's profile is a public profile. This means that to get Tweets from any Twitter user's timeline, we will need to make an authenticated request via OAuth. In case you want to understand what oAuth is all about, read it here.
 
This article will explain to you how to authenticate your website/application to display Tweets from your timeline. In case you are just interested in displaying Tweets from your timeline on your website and nothing much, you do not need to dig into this article, rather you can do it using Twitter Widgets and if you are not happy with the way it looks on your website and you want to customize it, read this article on customizing the embedded widget.
 
If you are more technical, read on! To be able to connect Twitter using OAuth, we need to do the following 2 very important things:
  1. Create a Twitter App
  2. Connect with the App using a library in the language of your choice.
The very first thing that you will need to do is to create an app on Twitter. So, let us start building an app on Twitter. To create an app on Twitter, use the following procedure:
  • Go to https://dev.twitter.com/apps  and log in with your Twitter credentials.
    TwitterApp1.jpg
     
  • Since this is the first time you are logging into this screen, you will see a button to "Create a new application":
    TwitterApp2.jpg
     
  • Enter the following details on this screen:
    • Name: Enter a name to your Twitter app
    • Description: Provide a short description to your app
    • Website: Normally the website address where you will want your app to be running on (in other words, where you want to display your Tweets)
    • Callback URL: Can be left empty
    • Agree to the "Developer Rules of the Road"
    • Enter the CAPTCHA
    TwitterApp3.jpg
     
  • Hit "Create your Twitter Application". You will see a message that your app has been created successfully and you will see you Consumer Key and Consumer Secret.
  • At the bottom of the page. Click "Create my access token". You will see a message that your token has been successfully created.
    TwitterApp4.jpg
     
  • Once that is done, go to the "OAuth tool" tab of your app and copy the following fields to be used in your application:
    • Consumer Key
    • Consumer Secret
    • Access Token
    • Access Token Secret
    TwitterApp5.jpg
     
  • You are ready to code some lines in your application to get data from your timeline.
I hope you like this article!


Rebin Infotech
Think. Innovate. Grow.