Going social in Actionscript 3

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.

  1. 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.
  2. 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.

There are several blogged solutions out there, but the smoothest I’ve found revolves around using the JavaScript API in conjunction with an “xd_receiver.htm”. The user logs into their account after which a JavaScript callback passes a session key, a secret key, the user’s UID and your (hardcoded) API key to Actionscript where it is verified via the REST API. This does require a bit of a hack seeing as the AS3 API doesn’t normally allow the setting of the UID, but I’d say it’s worth the trouble:

1
2
3
4
5
6
7
8
import com.facebook.facebook_internal;

// 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.

I’ve created a singleton-based wrapper, which provides me with easy access to basic functionality such as login and stream publishing, along with an accompanying JavaScript file (I’ve been accessing this via a PureMVC proxy – abstraction overkill?! Maybe!). It’s not exactly the tidiest of classes, but is fairly descriptive along with some doc-blocks. Feel free to download a zip here or grab the latest source from within the milkisevil-toolbox on github (you’ll mainly be interested in the api.facebook package as well as the js and possibly html test page).

Of course, you’ll also be needing the Facebook Actionscript 3 API (and SWFObject if you’d like to play with the test html page).

Tags: , ,

4 Responses to “Going social in Actionscript 3”

  1. Brilliant solution dude. I’ve been surfing the net for past two days to find a reliable solution and almost all of them were either incomplete or I was just not able to understand them at all.

    Your JS Wrapper on top of the Facebook JS API is very good and scalable. Same goes to the AS wrapper.

    Nice one.

  2. [...] So then I started googling, trying to find a better way and soon found out that setting up the connect process in javascript is a better option even for flash applications. Though, there are a number of solutions out there to get you started using the Javascript API I am mentioning but I ended up using Philip Bulley’s solution. [...]

  3. Great stuff. Finally an easy example that actually works…

    Unfortunately, somehow I can’t make the loginComplete event works. I keep getting the “loginCanceled” event after pressing the “allow” button on Facebook’s dialog.
    Any clue?

  4. @RotemD
    Are you talking about the javascript callbacks? If not, have you tried uncommenting the alert() lines in the facebook.js loginComplete() and loginCancelled()?

    It would be good to know whether the js loginComplete() is firing at all and whether a session is being passed to it.

Leave a Reply