October 25, 2014
Hot Topics:
RSS RSS feed Download our iPhone app

Writing Facebook Applications Using Java EE

  • March 13, 2008
  • By PJ Cabrera
  • Send Email »
  • More Articles »

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.

Besides FBML, there are also FBJs for Ajax-like effects, and FBQL for querying user information in a SQL-like fashion, all within pages with <fb:> tags. Combine FBML, FBJs, and FBQL with a powerful Java MVC framework, and you can create complex apps that integrate cleanly with the Facebook UI.

Conclusion

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.

Resources

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/.


Tags: Facebook



Page 7 of 7



Comment and Contribute

 


(Maximum characters: 1200). You have characters left.

 

 


Sitemap | Contact Us

Rocket Fuel