Friday. Log Out! Shut down! Get out!

The Facebook Javascript API for flash websites

April 29, 2011by Adrian ╚śchiopuin DevelopmentNo Comments

One of the most challenging and, at the same time, entertaining task I was assigned to lately was to implement a functionality for a full-flash website (developed in Flex) that allowed it to communicate with Facebook and have it change the user’s status automatically.

Facebook is a huge social network and a wonderfully designed application. And, as many other large web apps, it supplies us with their very-own API – which is great. It allows us access to their huge collection of users and provides us with great opportunities for extension.

Facebook is evolving, and so is the code that allows us to communicate with it. The documentation, however, is very poor and part of it is outdated. Most of the AS3 samples provided on their website no longer work (shame on you, Adobe) and the methods lack description in the reference.The PHP code comes with no documentation what-so-ever.

But that’s ok – I said to myself – as the flash player does such a wonderful job in running javascript in the browser. The docs for javascript were there and allegedly up to date (even though they lacked in specificity).

I began the implementation but got stopped early in my tracks – the popup window for the Facebook login wouldn’t pop. FB.Connect.requireSession() was working well when called from an onclick handler but did nothing when it was executed by my AS3 code. Very frustrating: no errors, no messages, nothing.

So the digging began, and the deeper I went, the more fascinated I was by the wonderful design and quality of their code. I managed to track down the problem – requireSession() would halt if it wasn’t called from within a click handler, thus enforcing direct user interaction with the website.
FBIntern.Utility.get_isInUserActionCallstack() was responsible for this, so the easy way around it was a simple overwrite* – and voila!

The Facebook Javascript API is an excellent piece of work and I hope that sometime in the future they will update the documentation as well. It would have saved me a great deal of trouble if I knew from the start that some of their methods are only meant to be called in certain contexts.

All in all, though, it was a wonderful experience!

Adrian ╚śchiopu

What do you think?