Integrate java application with Facebook using graph api. « Intelligrape Groovy & Grails Blogs

Integrate java application with Facebook using graph api.

Posted by Anshul Sharma

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

  • Share/Bookmark
This entry was posted on November 14th, 2010 at 10:02 pm and is filed under Groovy . You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

3 Responses to “Integrate java application with Facebook using graph api.”

  1. hans says:

    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

  2. Source…

    read more here…

  3. I drop a leave a response whenever I like a post on a blog or if I have something to contribute to the conversation. Usually it is a result of the sincerness displayed in the article I looked at. And after this post Integrate java application with Facebook using graph api. Intelligrape Groovy & Grails Blogs. I was actually excited enough to post a comment :-P I do have 2 questions for you if you do not mind. Could it be simply me or do a few of the responses come across like they are written by brain dead people? :-P And, if you are writing on other online social sites, I’d like to keep up with you. Would you make a list all of all your public pages like your twitter feed, Facebook page or linkedin profile?

Leave a Reply