This blog is to help you to get Facebook Authentication through OAuth using Java. As Facebook is not offering any SDK for Java clients so with the use of a Json parser we are going to develop a small web application in order to use Facebook Authentication. You can download java Json jar from here http://www.java2s.com/Code/Jar/j/Downloadjavajsonjar.htm
First of all you need get registered with Facebook and need to Sign in into developer account.
After Sign In into Facebook Developer Account.
Go to my apps
Click Add a New App
Select website from there.
You have to give a name for your new app or you can choose from pre existing ones.
After giving a new name you have to click on create new Facebook app id.
Then you will be prompted to provide some necessary details.
Click on create app id.
you can skip the get started tutorial.
Now you will get dashboard page of your app. In which App Id and app secrete will be given which will be used by your application.
You can assign different user roles to different users by selecting the option role in context with your app. Here you can add or assign users in different roles to be used until your app is in development phase. You can also add multiple test user for you app as Facebook provides this feature to create multiple test users.
Go to the setting section of it.
Put your app domain there for example localhost or you can also put multiple domains there and then click on add platform. Select website from there. Here you have to provide the URL of your app where you need to be redirected after Facebook authentication eg: http://localhost:8080/myapp/fbhome
Click on save changes.
Create an Dynamic Web Project in eclipse.
Give name to your new Web Application as myapp.
Now create a Facebook login page for that.
Put the downloaded java-json.jar to lib directory.
For that I created a index.jsp under WebContent folder an add the following code to it.