Facebook – AS3 for Facebook – why is the login callback not being called

actionscript-3facebookfacebook-graph-api

We're developing a Flash site that integrates with Facebook heavily.

We've noticed a bug where, if a user is not logged into Facebook, and we try to log them in via Facebook.login in the AS3 classes provided by Adobe, the callback is invoked, but the parameters result:Object and fail:Object are BOTH null. If our user then tries to login again, it all works fine, returning the userid in result:Object if successful.

Is this a bug with Facebook itself? Has anyone seen this before? We're sure this wasn't happening about a week ago.

Facebook.login(onLogin, {perms:Config.FB_PERMISSIONS});

private function onLogin(result:Object, fail:Object):void {

   // first time this is called after the popup closes returns
   // result == null and fail == null 
   // second time around, results are as expected
}

Cheers,
Mark.

Best Solution

this is a way to connect to Facebook using Graph API. Everything is explained in comment. This is actually the connecting to facebook, no posting to walls or anything. That part can be found below this class.

package com.DAL 
{
    import com.facebook.graph.Facebook;
    import flash.events.Event;
    import com.facebook.graph.data.FacebookSession;
    import flash.events.EventDispatcher;
    import flash.events.MouseEvent;
    import com.fbLoginButton;
    import com.adobe.serialization.json.JSON;

    public class FBConnect extends EventDispatcher
    {
        /******************************************
        *   Variables
        ******************************************/
        private var _applicationID:String;
        private var _extendedPermissions:Object;

        /******************************************
        *   Constants
        ******************************************/
        public static const CONNECTED:String = "CONNECTED";

        /******************************************
        *   Properties
        ******************************************/             
        public function get applicationID():String
        {
            return _applicationID;
        }

        /******************************************
        *   Constructor
        ******************************************/
        public function FBConnect() 
        {
            super();

            //Set applicationid
            _applicationID = "YOUR_ID";

            //Set permissions to ask for
            _extendedPermissions = {perms:"read_stream, publish_stream, user_about_me, read_friendlists, user_photos"};

            //Initialize facebook
            Facebook.init(_applicationID);
        }

        /******************************************
        *   Methods
        ******************************************/     
        public function login(e:MouseEvent):void
        {           
            Facebook.login(handleLogin, _extendedPermissions);
        }

        private function handleLogin(response:Object, fail:Object):void
        {
            dispatchEvent(new Event(CONNECTED));
        }
    }
}

That should take care of connecting to facebook. If you want to post to walls or anything, you can find a small example below.

        /******************************************
        *   Constructor
        ******************************************/
        public function FBLogic() 
        {
            super();

            _connect = new FBConnect();
            _connect.addEventListener(FBConnect.CONNECTED, startLoaders);

            initLoaders();
        }

        /******************************************
        *   Methods
        ******************************************/

        ...

        public function post(message:String):void
        {
            var _params:Object = new Object();

            _params.access_token = Facebook.getSession().accessToken;
            _params.message = message;

            Facebook.api("/" + _userID + "/feed", messagePosted, _params, "POST");
        }

        public function messagePosted(response:Object, fail:Object):void
        {
            dispatchEvent(new Event(MESSAGEPOSTED));
        }

        public function login(e:MouseEvent):void
        {
            var _loginButton:fbLoginButton = e.target as fbLoginButton;
            _loginButton.alpha = 0;
            _loginButton.visible = false;

            _connect.login(e);
        }

If this doesn't do the trick you might have forgotten to add some code to your html file. Be sure to add the following code to the head of your html file:

<script type="text/javascript" src="http://connect.facebook.net/en_US/all.js"></script> 

And you also need a div called fb-root, declared like this.

<body>
    <div id="fb-root"></div>
    <div id="flashContent">
    </div>
</body>
Related Question