Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Facebook action script 3 API login/logout issue

I'm making mobile AIR app for Android using Flash builder 4.5, AIR 2.6, Facebook action script 3 API the latest version.

I have a problem with login/logout. I can login only one time - then my data caches somehow and Facebook automatically logs me in. When I call logout I receive response TRUE, but I don't really logout from system. Standard login dialog doesn't appear for me. I have already read a lot of articles on stackoverflow and open issues on official site, but none of them were helpfull. How can I solve this? Here is the code I use:

package
{
    import flash.display.DisplayObject;
    import flash.display.Sprite;
    import flash.display.Stage;
    import flash.display.StageAlign;
    import flash.display.StageScaleMode;
    import flash.events.Event;
    import flash.events.IOErrorEvent;
    import flash.external.ExternalInterface;
    import flash.net.URLLoader;
    import flash.net.URLRequest;
    import flash.system.Capabilities;
    import flash.system.Security;
    import flash.display.Loader;
    import com.facebook.graph.FacebookMobile;

        public class TestProj extends Sprite
        {
            public function TestProj()
            {
                super();

                //register to add to stage
                this.addEventListener(Event.ADDED_TO_STAGE, onAddedToStage);

                // support autoOrients
                stage.align = StageAlign.TOP_LEFT;
                stage.scaleMode = StageScaleMode.NO_SCALE;
            }

            private function onAddedToStage(event:Event):void
            {
                this.removeEventListener(Event.ADDED_TO_STAGE, onAddedToStage);

                FacebookMobile.init("195053007196177", initCallback);
            }

            private function initCallback(success:Object, fail:Object):void
            {
                var appPermissions:Array = new Array("read_stream", "offline_access", "publish_stream", "read_friendlists");
                FacebookMobile.login(loginCallback, this.stage, appPermissions);
                //FacebookMobile.logout(logoutCallback);
            }

            private function loginCallback(success:Object, fail:Object):void
            {       
//And here I always receive success with my UserID
//and login dialog don't appears to me before this  
                if (success)
                {
                    trace("login ok");
                }
                else
                    trace("login failed");
            }

            private function logoutCallback(success:Object):void
            {
//here I reseive "TRUE" always!!
                trace(success);
            }

        }
    }
like image 596
yozhik Avatar asked Aug 07 '26 13:08

yozhik


2 Answers

You're only passing the 1st argument of logoutCallback to your logout method. If you add in the 2nd argument of your site url specified for your app, it should clear it out the html cookie for that window. Also, set FacebookMobile.manageSession = false;

            FacebookMobile.logout(logoutCallback, "http://your_app_origin_url");

There is a potential, related bug that involves Desktop and Mobile not accessing or clearing the access token's the same way. For that, there's a hack that describes exposing the access token in FacebookMobile, then manually calling the "logout" method with the access token. The issue is described here, including a method called "reallyLogout". If what I've written above doesn't work, implement "reallyLogout".

When you log out, your app clears the local session but does not log you out of the system. This is clearly defined in the documentation for logout. Think about it, if you're logged into Facebook on your Smartphone, Web Browser, and now this Mobile Desktop App, and suddenly you log out... it shouldn't log you out EVERYWHERE, just within that browsers session. So pass that 2nd parameter.

like image 153
Dominic Tancredi Avatar answered Aug 10 '26 14:08

Dominic Tancredi


I've had this exact problem, and after trying numerous fixes, this finally seems to work:

The default logout functionality seems to not be properly clearing cookies via the FacebookMobile actionscript API. The solution in comment #33 here worked for me, reproduced here. Make sure to sub in your own APP_ID:

function logout(e:MouseEvent):void {
  FacebookMobile.logout(onLogout, "https://m.facebook.com/dialog/permissions.request?app_id=APP_ID&display=touch&next=http%3A%2F%2Fwww.facebook.com%2Fconnect%2Flogin_success.html&type=user_agent&perms=publish_stream&fbconnect=1");
}

function onLogout(result:Object):void
{
  trace("Perfect Log Out!")
}
like image 39
Jeff Ward Avatar answered Aug 10 '26 13:08

Jeff Ward



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!