I’ve got Facebook games coming out of my ears right about now! This one is to accompany the new movie ‘The Girl Who Played With Fire’ – out in cinemas later this month.
Hot on the heels of ‘Pass It Around Pizza’ comes ‘Hungry For Action’; the second social game for Pizza Hut UK. Supporting the release of the new A-Team movie, the premise is simple; smack the living daylights out of as many soldiers as possible.
Quite often it’s advisable to treat unique IDs as a string, particularly when using a third party API, as you never know when they may migrate from a numeric to alphanumeric format.
The Facebook Actionscript API is no exception. In a recent project, I’d already been treating user’s UIDs as a string, but got caught out when calling the GetAppUsers API method. This essentially returns the UID of each friend who has the same Facebook application installed. Instead of returning a set of string values, it returns an array of number values.
Storing this array within Actionscript doesn’t appear to be hazardous. The problems arise when sending that array via remoting (in this case using a sfAmfphp gateway).
Facebook currently employ two formats of UID:
The old format will be serialized and received by the PHP gateway as expected, whereas PHP will output the new longer format as, for example, 100000792322E+14.
Moral of the story: iterate through the array returned by GetAppUsers and cast all values to String.
public function getAppUsersComplete(event:FacebookEvent):void
var uidFriends:Array = event.data['uids'];
// Convert all uidFriend uids from Number to String because AMFPHP messes this up (converts large int values to float)
for(var i:int = 0; i<uidFriends.length; i++)
uidFriends[i] = uidFriends[i].toString();
Tags: facebook api
UPDATE: Read my “Pass It Around Pizza” article on the Blue Barracuda blog. Aimed at marketers, it looks at the benefits of using in-game incentives/virtual gifts and rewards in conjunction with the Facebook Platform.
UPDATE Nov 2010: This requires the old REST API Facebook_library_v3.4_flash.swc, which has now been deprecated in favour of the Graph API. Please feel free to fork this for use with the new GraphAPI SWC. There is a little more info on this in the comments. I’d love to update it myself, but not sure when that might happen at the moment :-/
Ideally, the fb:multi-friend-selector would allow the setting of a callback which would return the UIDs of the selected friends. It would then be down to the developer to choose what to do with them.
So, I decided to recreate the fb:multi-friend-selector directly in Flash. It will allow you to input an array of uid strings and later return a FacebookUserCollection featuring the selected users. Unfortunately I haven’t created this to be a fully resizable component, it simply does what it says on the tin. Hopefully, you may find that this gets you out of a sticky situation once you realise the shortcomings of the FBML fb:multi-friend-selector.
You can download it from the milkisevil-toolbox on github. You’ll need to add the “lib/milkisevil/FacebookComponents.swc” to your project and create a new instance of the “com.milkisevil.ui.facebook.MultiFriendSelector” class.
Here’s a rough guide to how you might want to instantiate the MultiFriendSelector:
// Don't forget to make the following imports where appropriate
// And the following inside your class
private var multiFriendSelector:MultiFriendSelector;
private function showFriendSelector():void
multiFriendSelector = new MultiFriendSelector( facebook, 16 );
multiFriendSelector.title = 'Your friends';
multiFriendSelector.subtitle = 'Irritate the hell out of your friends!';
multiFriendSelector.addEventListener( MultiFriendSelector.STATUS_EVENT, multiFriendSelectorStatus );
addChild( multiFriendSelector );
private function hideFriendSelector():void
removeChild( multiFriendSelector );
multiFriendSelector = null;
private function multiFriendSelectorStatus(event:StatusEventEnhanced):void
trace('exec multiFriendSelectorStatus: ' + event.code);
var selectedUsers:FacebookUserCollection = multiFriendSelector.getSelected();
var uidList:Array = ;
for(var i:int = 0; i<selectedUsers.length; i++)
var facebookUser:FacebookUser = selectedUsers.getItemAt(i) as FacebookUser;
uidList.push( facebookUser.uid );
// Now do some custom stuff with those uids
myCustomMethod( uidList );
The last couple of weeks have allowed me to get intimate with AS3 implementations of the main social network’s APIs. I first started out playing with Adobe’s Flash Platform Social Services which is basically a layer providing access to Gigya (which in turn is an abstract API providing uniform access to all of the main social networks). As you can probably imagine, this also comes with a couple of drawbacks.
- Gigya aims to provide the ‘make one call, push to many’ approach. This is one of the reasons that the full spectrum of services for one social network aren’t available, largely because there won’t be a uniform equivilant on another network.
- The other reason, is that we’re relying on a single API vendor (Gigya) to update as and when every other API vendor updates. So where a great new service might be made available on Facebook, you’ll likely be waiting a while until Gigya provides an updated interface.
Not great. So putting aside a greed to support every social network under the sun, I swiftly moved to and focused on the the most popular (and arguably the best), the Facebook Actionscript API. This is basically an Adobe supported AS3 interface to Facebook’s REST API. The majority of it is very straight forward to use, and is up to date with the latest of Facebook’s features. The biggest pain, though, has been offering a smooth login experience.
// Create a WebSession passing in your API key, the secret key and session key
webSession = new WebSession( apiKey, secret, sessionKey );
// Force set the uid (don't forget to import the "facebook_internal" namespace)
webSession.facebook_internal::_uid = uid;
facebook.startSession( webSession );
This solution will use those nice AJAX-populated dialogue boxes, so don’t forget to set wmode=”transparent” on your embed.