Showing posts with label Facebook API. Show all posts
Showing posts with label Facebook API. Show all posts

View Facebook API Code

Before going to proceed further, following liberary must be available in your class path,
  • activation-1.1.jar
  • commons-lang-2.2.jar
  • commons-logging-1.1.1.jar
  • facebook-java-api-3.0.2.jar
  • facebook-java-api-annotation-processor-3.0.2.jar
  • facebook-java-api-schema-3.0.2.jar
  • jaxb-api-2.1.jar
  • jaxb-impl-2.1.9.jar
  • json-20080701.jar
  • restfb-1.6.12.jar
  • runtime-0.4.1.5.jar
  • stax-api-1.0-2.jar
We are using following two API to communicate with Facebook.
  1. Facebook API
  2. RestFB API
Create logging.properties file under src directory in your project. 

logging.properties 
create new servlet file which handles incoming and outgoing request from our application. We required only file to handle all the request. No need to worry about rest of the thing right now, just enjoy programming to integrate Facebook API. 

MainServlet.java  As you can see from the code, when the servlet called first time at that time code was null so it comes under the else part and redirect to facebook to validate their credential. 

once facebook gets approved it will return back with either code or token, depend upon our configuration.We have provided redirect_uri parameter to facebook to indicate that response came from facebook will be proceed by this servlet. 

in our case both servlet are same. Means we are using the same servlet to send a request to facebook and proceed response from facebook. Once we received code/token, one can send a request to get an access token of your application, Access token play very important role for communicating. 

Note : I have changed my API_KEY & SECRET_KEY so you can changed with yours. If you don't know how to get API & Secret key then visit this post Steps to FBI API. Before going to start with Facebook integration, Please refer documentation first that would be easy to understand code as well as flow.

posted under , | 1 Comments

Step by Step guide to integrate Facebook API using java

In this section, I will provide you step by step guide to integrate Facebook API using java. It would be very easy to implement Facebook API  but for that we need to follow certain steps in proper sequence.

Step 1  :  Create account on Facebook website. http://facebook.com/
Step 2  :  Login into your account on Facebook.
Step 3  :  Now go to following URL : https://developers.facebook.com
Step 4  :  You will find app tab in top menu, click to continue or directly go to following URL https://developers.facebook.com/apps  
Step 5  :  Now click on create new App.
Step 6  : This will open new model dialog box and ask you for app name. Please provide unique application name. skip rest of the details and click on continue.
Step 7  : This will redirect you to show list of registered application now click on edit settings. This page is very very important because it provides your application id (app-id) as well as application secret(app secret). Copy both app-id and app-secret to another file and save it. both credentials are required to communicate with Facebook API.
Now go under following section: Select how your app integrates with Facebook
and select Website with Facebook Login and provide Site URL path to your local web application path (in my case)  like :  http://localhost:8084/FBAPI
and make sure that you have enabled sandbox mode and save changes. 
That's it . There are many other settings but they are optional, you can set them as per your requirement. 
Step 8 : Now last and final step to set Facebook API to work. Getting an access token. Access token perform very important role while communicating with Facebook API. Without an access taken, it was not possible to get any information from Facebook API. These is a only step where people gets confused where to get an access token of our application. Don't worry I have provided steps to get an access token of your application.
Step 9 : Go to https://developers.facebook.com/tools/explorer
Facebook provide very powerful utility to get an access token of your application and provide a very dynamic feature to access Graph API on the fly.
We will discuss it later on. Now when you open above link you will find your list of application in selection box. Now select proper application if you have more then one application in your account otherwise no need to select any application. once you select application, now click on Get Access Token button to continue.
These will open new pop up box to select list of permission your application will be required from user to access their private data.
select permission details as per your requirement and finish it.
You will see your generated token inside the text box.
Note : Always keep in mind that if you change your permission, you request token gets changes accordingly so after every modification in permission you will get new access token. Access token plays very important role to communicate with Facebook, we have to send access token as parameter on each request.

  


posted under , | 1 Comments
Older Posts Home

Followers

Powered by Blogger.

Populares

Custom Search