Social Java
Social Application development using Java
HelloSocialJavaWorld Application:
Description:
This example shows the phrase Hello Social Java World in a Facebook application.
In the prerequisite and configuration sections, I show the steps to add this application to Facebook. Facebook configuration options are illustrated. The Facebook Developer Application is used.
The servlet source is covered in the code review section.
Prerequisites:
The Java Code :
THe HelloSocialJavaWorld servlet prints "Hello Social Java World" as a response when accessed. The doPost and doGet methods both do this.
Download Source
import javax.servlet.http.*;
import java.io.IOException;
import javax.servlet.*;
import java.io.PrintWriter;
public class HelloSocialJavaWorld extends HttpServlet {
PrintWriter servletOutput;
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
servletOutput = res.getWriter();
res.setContentType("text/html");
servletOutput.println("Hello Social Java World");
}
public void doPost(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
servletOutput = res.getWriter();
res.setContentType("text/html");
servletOutput.println("Hello Social Java World");
}
}
Configuration:
In the Facebook Developer Application, I chose to Add a New Application.
I used HelloSocialJavaWorld as the name for the application.
The screenshots below go through this step-by-step.
What is the Callback URL?
The brief explanation is that this is the page that Facebook calls to display and run this application.
In this example, it is the servlet we created. Note that the servlet lives on socialjava.com and not Facebook
In a future example about authentication, I'll cover this in more detail.
What is the Canvas URL?
This is the page that is displayed by Facebook when the application is accessed.
Note that the Post-Add URL and Side Nav URL use this value.
This is the page that will be displayed after the user adds the application or when they access it from the side navigation area.
Below are the settings for this application that Facebook shows when done:
Contact Email:
Support Email:
Callback URL: http://www.socialjava.com/servlet/HelloSocialJavaWorld/
Canvas URL: http://apps.facebook.com/hellosocialjavaworld/
FBML/iframe: FBML
Dev Mode?: Off
Application Type: Website
Post-Add URL: http://apps.facebook.com/hellosocialjavaworld/
Side Nav URL: http://apps.facebook.com/hellosocialjavaworld/
Private Install?: No
Description:
Java Servlet Facebook Application
Servlet shows "Hello Social Java World"
Source code available
Add new application
Set Callback URL, Canvas Page, use FBML, and make this a web site application.
Set up how the application is added to Facebook
Describe the application and set Default FBML.
FBML is Facebook markup language. If the application is added, it will appear on the user's profile. In that case, the default FBML will be displayed
Set the navigation
Optionally add an icon for the application
When user adds this application they will see this page.