import java.io.IOException; import java.io.PrintWriter; import java.util.*; import javax.servlet.ServletException; import javax.servlet.http.*; import org.w3c.dom.Document; import com.facebook.api.*; public class AbstractFacebookServlet extends javax.servlet.http.HttpServlet implements javax.servlet.Servlet { protected static final String FB_APP_URL = "http://apps.facebook.com/javapages/"; protected static final String FB_APP_ADD_URL = "http://www.facebook.com/add.php?api_key=bd5896c1ffe7ebd69e07bbd720d357ba"; protected static final String FB_API_KEY = "bd5896c1ffe7ebd69e07bbd720d357ba"; private static final String FB_SECRET_KEY = "8e5bce24cb11fc7d22ed043ebc69860f"; FacebookJsonRestClient json=null; public AbstractFacebookServlet() { super(); } /* * This method is used by all of the application's servlets * (or web framework actions) to authenticate the app with * Facebook. */ //protected FacebookRestClient getAuthenticatedFacebookClient( protected FacebookJsonRestClient getAuthenticatedFacebookClient( HttpServletRequest request, HttpServletResponse response)throws IOException { IFacebookRestClient json; IFacebookRestClient xml; // PrintWriter servletOutput; // output of servlet. HTML or FBML out // String loginPage = "http://www.facebook.com/login.php?api_key="+FB_API_KEY+"&v=1.0&canvas=true"; //String aboutPage = "http://www.facebook.com/apps/application.php?id=20063872087"; // servletOutput = response.getWriter(); // response is sent to ServletOutput // response.setContentType( "text/html" ); // do authentication // String user =null; String sessionKey;//=null; sessionKey = request.getParameter(FacebookParam.SESSION_KEY.toString()); // Session Key passed as request parameter if (sessionKey==null) { // If there is not session key, they user not logged in /* String newFacebook = request.getParameter("fb_sig_in_new_facebook"); if (newFacebook.equals("1")){ loginPage = "http://www.new.facebook.com/login.php?api_key="+FB_API_KEY+"&v=1.0&canvas=true"; //aboutPage = "http://www.new.facebook.com/apps/application.php?id=20063872087"; } servletOutput.println(""); // Facebook Redirect to login page */ return (null); } else{ // user is logged on json = (FacebookJsonRestClient) new FacebookJsonRestClient( FB_API_KEY, FB_SECRET_KEY, sessionKey); /* try { json.notifications_send("testing 1 2 3"); } catch (FacebookException e) { System.out.println("trying notification " + e); } catch (IOException e) { System.out.println(e); } return ((FacebookJsonRestClient)json); } */ return ((FacebookJsonRestClient)json); } /* Facebook fb = new Facebook(request, response, FB_API_KEY, FB_SECRET_KEY); String next = request.getServletPath().substring(1); if (fb.requireLogin(next)) return null; */ //return fb.getFacebookRestClient(); //return json; /* String user =null; String sessionKey=null; //auth_token=edc9cbd93649f43d606ea3420cb1fb75 String auth = request.getParameter("auth_token") ; if (auth==null) { // If there is not session key, they user not logged in return null; } else{ Facebook fb = new Facebook(request, response, FB_API_KEY, FB_SECRET_KEY); return fb.getFacebookRestClient(); } */ } }