Flashbelt 2008 – Minneapolis, MN

2008:06:11

Just got back from Flashbelt here in Minneapolis. Here’s a quick rundown.

Flash 10 Graphics

Lots of cool graphics manipulations tools. 3D Display API, pixel shader API, high performance typed Vector class (40% faster than standard array).

Most of the cool stuff was in definitely in the Actionscript graphics space. Its evident Adobe wants developers to provide a UI experience that is as mind blowing as possible with a fairly simple development model as opposed to traditional graphics APIs.

The pixel shader API performance was very impressive as they demoed it rendering realtime with video and animation.

Space 150 – Use Flash, Skip Deal w/ The Devil

The Space 150 presentation covered how to do flash sites that still functioned under non-flash player environments and play nice with SEO without having to resort to double development. The answer, as many people know now, is to make hybrid sites.

Space 150 provides a process called ‘Faust’ that targets this problem. Key points IMO -

  • Search Engine Friendly
  • Single Codebase

Logging in with Facebook Java API

2008:06:03

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

  1. Download facebook-java-api. Make sure this jar and all of the required jars are in your project’s classpath.
  2. 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.

  1. Construct your client with your API key and Secret
  2. Obtain an auth token
  3. 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();
    }
  }
}