Monday, June 29, 2009

Using FaceBook API from ActionScript

About two month ago, FaceBook announced it's Open Stream API (also known as Facebook Connect) that allowed applications to interact with FaceBook and replicate most of it features.

To demonstrate this, they got their partner, Adobe to create Facebook for Adobe AIR, which is an application that runs on your desktop. You log in with your Facebook account and can then read your News Feed and publish content to your Wall and friends' News Feed.

The source code for this application is publicly available and I recently took a look at it.
(UPDATE: there is now a project on Google Code for it too)

Of particular interest is how it communicate with FaceBook:


var request:URLRequest = new URLRequest("http://api.facebook.com/restserver.php");
request.contentType = "application/x-www-form-urlencoded";
request.method = URLRequestMethod.GET;
request.data = urlArgs; // a flash.net.URLVariables object


But all this is nicely encapsulated for you in the "fb" package.

Some uses would be to upload screenshots and post achievements in Flash games directly to your FaceBook wall. Or it can be used to allow easy multiplayer game matchmaking with your friends.


The source code from this application also show some advanced ways to display HTML formatted text using ActionScript (and Flex). Thus, its a rather nice example.


Also, here is a tutorial (from Adobe) that walks beginners like me on how to register a FaceBook application and get its API key, however it uses Flex instead of Flash.

No comments:

Post a Comment