EDIT: Fixed most of the problem (but not too sure why). Check the bottom of the post for my note.
I am doing my first AS3 Facebook project from scratch, so apologies for any stupid mistakes.
Anyhow, I created a simple class that init()’s the Facebook class object and prompts you to login if there is no getSession() currently in place. Now the problem is I can never get anything but NULL out of getSession() and calling Facebook.login() doesn’t do anything at all.
You’ll see in the code that Facebook.login() is conditional based on whether or not one can getSession(), but I have tried this without that check as well and I don’t even get the callback fired.
Any ideas?
I followed a tutorial on http://www.permadi.com/blog/2011/02/using-facebook-graph-api-in-flash-as3-1-5/ just in case there’s something blatantly wrong in my code (it’s his fault).
Code below:
public function init():void {
Facebook.init(_appID, checkLoginStatus, null, _accessToken, true);
}
// facebook methods ----------------------------------------------------- /
private function checkLoginStatus(response:Object, error:Object):void {
if (Facebook.getSession() && Facebook.getSession().accessToken){ configLoginData(); }
else if(!error) { promptLogin(); }
}
private function promptLogin():void {
$requireLogin.dispatch();
}
// login / logout ------------------------------------------------------- /
public function login(e:* = null):void {
Debug.log("Facebook PROMPT LOGIN " + Facebook.getSession(), Debug.GREEN);
if(Facebook.getSession() && !Facebook.getSession().accessToken){
Facebook.login(checkLoginStatus, {perms:"publish_stream"});
} else {
Facebook.logout(logoutComplete);
}
}
I also have it running off of my server which is properly hooked up to an App (as required). You can see it here: http://themoleking.com/laboratory/facebook_as3/FacebookAPI.html
OK, so I figured it out by digging through the Facebook API code.
If you enter oauth=true when you are calling Facebook.init(), it will automatically make all session calls NULL.
I don’t know enough about the API yet to know why that is, but at least I’m making some progress 🙂