Facebook is no longer maintaining its Java api.

Luckily the Java community is large enough to support an alternate project called, appropriately, facebook-java-api. This is hosted on google code and is well done.
My only issue – how to get going when you’re at square zero with the Facebook API.
Prep work
- Download facebook-java-api. Make sure this jar and all of the required jars are in your project’s classpath.
- Register a Facebook Application. You’ll need a Facebook account to do this. This creates your API key and Secret for authenticating Facebook users with your application.
About Facebook Application Authentication
Authenticating with the Facebook client API is pretty straight forward.
- Construct your client with your API key and Secret
- Obtain an auth token
- Authenticate a user with the auth token
Step 3 requires you to redirect the user to Facebook hosted URL. This is straightforward if you are building a web application. If you are developing a desktop application, you’ll need to open a browser and have them enter the information there.
Your users will be greeted with something like this -

Replace the red strike-throughs with your application name
After they enter their login information, they will have created a session that is associated with your auth token that you obtained.
The Code
The following code sample demonstrates authenticating your application, logging a user into your application and finally fetching the user’s friend list. You’ll need to add your package and import statements as necessary.
/**
* FacebookClient
*
* @author Mitch Coopet, Code 42 Software, Inc.
*/
public class FacebookClient {
public static String API_KEY = “YOUR API KEY”;
public static String SECRET = “YOUR SECRET”;
public static void main(String args[]) {
// Create the client instance
FacebookRestClient client =
new FacebookRestClient(API_KEY, SECRET);
client.setIsDesktop(
true);
// is this a desktop app
try {
String token = client.auth_createToken();
// Build the authentication URL for the user to fill out
String url = “http://www.facebook.com/login.php?api_key=”
+ API_KEY + “&v=1.0″
+ “&auth_token=” + token;
// Open an external browser to login to your application
Runtime.getRuntime().exec(“open ” + url); // OS X only!
// Wait until the login process is completed
System.out.println(“Use browser to login then press return”);
System.in.read();
// fetch session key
String session = client.auth_getSession(token,true );
// obtain temp secret
String tempSecret = client.getSessionSecret();
// new facebook client object
client = new FacebookJaxbRestClient(API_KEY, tempSecret, sessionKey);
System.out.println(“Session key is ” + session);
// keep track of the logged in user id
Long userId = client.users_getLoggedInUser();
System.out.println(“Fetching friends for user ” + userId);
// Get friends list
client.friends_get();
FriendsGetResponse response = (FriendsGetResponse) client.getResponsePOJO();
List<Long> friends = response.getUid();
// Go fetch the information for the user list of user ids
client.users_getInfo(friends, EnumSet.of(ProfileField.NAME));
UsersGetInfoResponse userResponse = (UsersGetInfoResponse) client.getRepsonsePOJO();
// Print out the user information
List<User> users = userResponse.getUser();
for (User user : users) {
System.out.println(user.getName());
}
} catch (FacebookException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}