My favorites | Sign in
Project Home Downloads Wiki Issues Source
Project Information
Members

Overview

Facebook provides a Java-based API, but I wanted a slightly different API for a few reasons:

  • The Facebook Java API returns org.w3c.Document for calls, which is quite a pain to work with. I prefer using JSON. Javabook uses json-lib, which is a good JSON library that is getting better by the month. It provides conveniences for JSON->Java bean mapping.
  • The Facebook Java API uses the JDK's HTTP client, which is quite poor. The Apache Jakarta Commons HttpClient that Javabook uses is a much better.
  • I wanted to incorporate logging and request latency measurement. Javabook uses Apache Jakarta Commons Logging, which integrates nicely with many Java people's existing logging infrastructure.
  • I prefer to turn certain exceptions (such as invalid sessions) into specific exceptions that can be caught and handled by the application.
  • I prefer separating the APIs for session-based and non-session-based Facebook methods into separate classes.
  • While the Facebook Java API is open source, there's not an obvious community process by which contributions can be incorporated.
  • I wanted something that could be a Maven package.

None of these are criticisms--I find the Facebook Java API generally well coded; I just have different requirements.

Javabook Limitations

  • The Javabook client API is only for Web-based applications. Desktop applications cannot use this API, at least right now.
  • The Javabook client API does not include all the read methods that the Facebook API does, as nearly all data can be requested through FQL. The Javabook API requires you to write FQL.
  • The API is currently missing a number of methods, like dealing with photo albums.
  • The API is mostly for Facebook applications that use FBML rather than iframes and applications that aren't using the Facebook platform.

Quick Start

Here's how you can make an FQL query for a user given an auth key (e.g., one that you receive from the FB login procedure).

      String apiKey = ""; // YOUR API KEY
      String secret = ""; // YOUR SECRET

      // Just create one of these for your app/process
      FacebookRpcClient fbRpcClient = new FacebookRpcClient(apiKey, secret);

      // You just need one of these for your app, too
      FacebookClient fbClient = new FacebookClient(fbRpcClient);

      String authToken = ""; // an auth token you've received
      
      // creates a session from the auth token
      FacebookSession session = fbClient.createSessionKeyForAuthToken(authToken);
      FacebookSessionClient fbSessionClient = new FacebookSessionClientImpl(App.getServer().getFacebookRpcClient(), session);

      JSONObject obj = fbSessionClient.queryForObject("select first_name from user where uid=" + session.getUid());

      String name = obj.getString("first_name");
Powered by Google Project Hosting