Integrate java application with Facebook using graph api.

14 / Nov / 2010 by Anshul Sharma 5 comments

These are few basic steps which will help you to integrate your java application with facebook using facebook graph api.

Steps :

1) Register your application at http://www.facebook.com/developers/
2) Facebook will return Consumer Key and Consumer Secret for your application.

3) Create a login action:

String facebookPermissions = FacebookPermissions

// Login Action
String callbackUrl = "ApplicationUrl/controller/action"
String facebookAuthorizeUrl = "https://graph.facebook.com/oauth/authorize?client_id=FacebookApiKey&redirect_uri=callbackUrl&scope=facebookPermissions"  //             
redirect(url: facebookAuthorizeUrl)

4) Create a callback action .

///  Call back action: Where the facebook will redirect after succesful authentication.

String authCode = parms.code
String facebookTokenUrl = "https://graph.facebook.com/oauth/access_token?client_id=FacebookApiKey&client_secret=FacebookSecretKey&code=${authCode}&redirect_uri=callbackUrl&scope=facebookPermissions"            
URL url = new URL(facebookTokenUrl)
String response = url.text
// Retrieve the access token from the response

6) Persist the access token for future use. The access token never expire until the user explicitly rejects the application from his settings.

Hope this helped!

Cheers!

Anshul Sharma

Tag -

FOUND THIS USEFUL? SHARE IT

comments (5)

  1. ajay

    i am using same api for FB login but i m facing an problem me getting null in session after successful authentication

    Reply
  2. Dino Gaffey

    Cool post. I have a site too. it’s about Twitter Followers, how you can build them and use this traffic source for monetization. Check it out, more traffic means more cash!

    Reply
  3. jai

    Hi anshul ….could u plz give me the step by step procedure …how to login into my java application via facebook account…plzzzzz

    Reply
  4. hans

    hi men, I need download the api for JAVA, know you authentic users with a aplication of desk? please guy, is for my proyect of the university.

    thanks

    Reply

Leave a comment -