OAuth with Facebook

Most of the applications over web these days need to get connected with each other. With the surge of Social Aware applications people started integrating all of their social application in one location.  Following is my attempt to solve the "Complex" but easy puzzle for novice developers

To start with i’ll demonstrate how to Login with Facebook and details of facebook user into your application

Lemme first explain what OAuth means in Brief.  Below is the diagram which explains

First we call Service provider with  ClientID  / CallBack URL  and Some additional Parameters based on Service provider you use

Then if we pass the right parameters then Service provider will give us a call back to given callback URL with Authorization Token and some parameter that states time to live

Now we can use this Authorization token in our subsequent requests to Service Provider Provided services

Here is example of facebook

Step 1

Goto Facebook developer Page

Step 2

Register your App. You will get you app key/secret etc

Step 3

Now goto this sample URL to get your token

Test with this URL


Replace Corresponding Tokens for your Application


Step 4

Once you get Call back get the access_token from the request and store it






Get user Data using the above token.


This gets user data in following format

   "id": "100000131478113",
   "name": "Ashwin Kumar",
   "first_name": "Ashwin",
   "last_name": "Kumar",
   "link": "http://www.facebook.com/profile.php?id=100000131478113",
   "birthday": "06/24/1984",
   "hometown": {
      "id": "103095893064172",
      "name": "Rajahmundry"
   "location": {
      "id": "103129393060364",
      "name": "Allentown, Pennsylvania"
   "work": [
         "employer": {
            "id": "111926488822704",
            "name": "Freelancer"
         "position": {
            "id": "130875350283931",
            "name": "CEO & Founder"
         "start_date": "0000-04",
         "end_date": "0000-00"

Njoy integrating facebook to your application. Subsequent series will Cover Google/Twitter/LinkedIn/Yahoo Integration. Also writing a java library for this.. Will share that in opensource once done

Njoy playing with social apps….


6 thoughts on “OAuth with Facebook

  1. Thanks for a marvelous posting! I actually enjoyed reading
    it, you could be a great author.I will make certain to bookmark your blog and will eventually
    come back sometime soon. I want to encourage you to continue your great writing, have a nice day!

  2. Its lioke you read my mind! You seem to now so mucfh about this,
    like you wrte the book inn iit or something.
    I think that yyou could do wth a few pics to drive the message home a
    bit, but other than that, this is magnificent blog. An excellent read.
    I will definitely be back.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s