So Adobe and Facebook came together a few months ago and released a full blown API for Flash/Actionscript 3, well released maybe more re-branded an existing API by Jason Crist. Anyway the API is very detailed, and as far as I aware well documented. Thought after a few weeks it’s probably worth looking into, as Facebook is still a buzzword which still holds a lot of weight.
In my opinion there are two types of application which will use the Facebook Flash API, the first being get and display apps. These are applications which get a users data and display information, think of the Last FM widget which display your top songs. Secondly an applications which take advantage of Facebook’s networking ability like Connect Red Bull. No doubt there are probably more types of application but there’s nothing like making a wide sweeping statement!

Anyway I’m just going mention a couple of things, about this little get and display application I’ve quickly made which gathers list of the users friends and displays specific information. Below I have briefly listed the various steps in the process to get this information, as you can see the process is unlike other API’s which after making a call send you back an xml document of information. For instance twitter will give a xml document containing all your friends information. Instead with the Facebook API you make request for a friends list, get a list of unique id’s in return and then have to make individual user queries on the unique id’s. I imagine I’ve completely missed something here, but I may be right if this is the case it’s probably due to the scale of Facebook, the data available and the potentially security risk. Making individual user queries also means the amount of being data requested is smaller i.e you receive only what ask for.
1. User logins into Facebook
2. User confirms login
3. Start Facebook session
4. Fetch users friends with users unique id
5. Receive unique id of users friends
6. Fetch specific data for each of the users friends
7. Receive data for each of the users friends
8. Repeat 6 and 7 till complete
9. Do whatever.
The little application I’ve produced, just displays a selected number of the Facebook user friends and some basic information name, picture, DOB, about me. Perhaps next time I’ll try some networking and add some error handling. Here’s the application.
Flash is displayed here
And now some actionscript code.
By this stage the user has initialized the Facebook session by logging into Facebook, then confirmed they have done so and I have Completed a FriendList Request. Below I’m pushing all the unique id’s into an array, so they’re slightly more accessible then shuffling the array so I have a random order of friends each time.
private function getFriendsInfoResponse(event:FacebookEvent):void
{
event.target.removeEventListener(FacebookEvent.COMPLETE, this.getFriendsInfoResponse);
var responseData:GetFriendsData = event.data as GetFriendsData;
for(var i:Number = 0; i
{
this.uniIdArray.push(responseData.friends.getItemAt(i).uid);
}
ArrayShuffle.shuffle(this.uniIdArray);
this.loadFriend();
}
Simple load request of a user's data by via a unique id.
private function loadFriend():void
{
var call:FacebookCall = facebook.post(new GetInfo([this.uniIdArray[this.loadCount]], ['uid', first_name', 'last_name', 'pic_small', 'about_me', 'birthday']));
call.addEventListener(FacebookEvent.COMPLETE, this.getFriendInfoResponse);
}
I've created an ProfileObject class, which consists of various getters and setters for the requested data. And I know I've declared variables halfway into a function, but the first few lines handle errors.
private function getFriendInfoResponse(event:FacebookEvent):void
{
event.target.removeEventListener(FacebookEvent.COMPLETE, this.getFriendInfoResponse);
if (!responseData || event.error)
{
trace("error ::" + this.loadCount);
this.loadFriend();
return;
}
var responseData:GetInfoData = event.data as GetInfoData;
var profileObj:ProfileObject = new ProfileObject();
profileObj.uid = responseData.userCollection.getItemAt(0).uid;
profileObj.firstName = responseData.userCollection.getItemAt(0).first_name;
profileObj.lastName = responseData.userCollection.getItemAt(0).last_name;
profileObj.profilePic = responseData.userCollection.getItemAt(0).pic_small;
profileObj.aboutMe = responseData.userCollection.getItemAt(0).about_me;
profileObj.brithday = responseData.userCollection.getItemAt(0).birthday;
this.profileArray.push(profileObj);
}