Writing Facebook Applications Using Java EE, Page 7
Using Facebook Markup Language (FBML)
Using the Facebook API within your servlet or other Java web framework controllers and actions gives you plenty of power to create your web app. But, there is more to the Facebook API than calling web services to pull out user profile and friend information. With FBML, you can use a markup language created by Facebook to integrate more fully with their platform with a minimum of fuss. For example, replace the main_page.jsp with the following code.
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %> <strong>myacebookapp Main Page</strong> <div> <fb:profile-pic uid="loggedinuser" size="small" linked="true" /><br> <fb:name uid="loggedinuser" useyou="false" linked="true" capitalize="true" />, you are special because you are using myfacebookapp! </div>
If you call main_page.jsp directly from your Facebook app's URL (for example, http://apps.facebook.com/myfbapp/main_page.jsp), you will see that these FBML tags produce the same output as the previous servlet and JSP EL example. Please also note that calling the JSP page directly means it didn't need to call getAuthenticatedFacebookClient() to authenticate with Facebook. These <fb:> tags aren't JSTL tags. The FBML parsing occurs on Facebook's servers, where the user has already logged in (otherwise, they couldn't access your application on Facebook's URL). Facebook also has ready access to the logged in user's profile information.
The Facebook social network is amazingly popular. To a great extent, the popularity of the service is a reflection of the popularity of the many applications created with the Facebook platform and its APIs. With improved libraries and example code, Java developers can hit the ground running and create more applications, to grow and extend the Facebook platform's reach with new ideas and social services.
- Facebook's Documentation pages: http://developers.facebook.com/
- Independently developed Facebook API for Java: http://code.google.com/p/facebook-java-api/
About the Author
PJ Cabrera is a freelance software developer specializing in Ruby on Rails e-commerce and content management systems development. PJ's interests include Ruby on Rails and open-source scripting languages and frameworks, agile development practices, mesh networks, compute clouds, XML parsing and processing technologies, microformats for more semantic web content, and research into innovative uses of Bayesian filtering and symbolic processing for improved information retrieval, question answering, text categorization, and extraction. You can reach him at pjcabrera at pobox dot com, and read his weblog at pjtrix.com/blawg/.
Page 7 of 7