Facebook AS3 API – Not getting response from auth.sessionChange or auth.login after password login?

Facebook’s AS3 API has handy built in methods for dealing with Javascript / Flash communication regarding authentication and other Facebook events. However, it doesn’t always work when it should. Consider the situation below:

Facebook.addJSEventListener('auth.login', onSessionChange);
var opts:Object = {scope:"publish_stream, user_photos, create_event"};
Facebook.login(onResult, opts);

In this case, we simply want to login and get the response from Facebook when our user has completed authentication. 

This works when the user is already logged into Facebook and Flash merely needs to register the application instance. However, if the user has to deal with the login prompt, the API does something funny. Flash will receive the response from Facebook but it will not necessarily be ready on Facebook’s server by the time you get it. Meaning your method receiving your auth.login event  will be called but if you try to do anything like …

Facebook.api('/me',onMeResult);

… your result will be an unauthenticated user error.

So the problem is that Facebook doesn’t assure it’s ready on its end before it sends you the response. My solution is terrible but it works — consider using a timer for your first API call with one second intervals from your auth.login method. In case the user cannot log in you might want to limit it to 5 cycles since no one will realistically time out longer than 5 seconds.

Leave a Reply