Facebook action script 3 API login/logout issue

2019-02-24 19:39发布

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);
            }

        }
    }

4条回答
Lonely孤独者°
2楼-- · 2019-02-24 19:47

Have had this Android Facebook clean logout problem the whole day, manage to solve it. Hope it helps. Here is my FB mobile handlelogin code to ensure all fb cookies and sessions are being removed and user will need to relogin.
Sometimes FB server is very slow. Its best to put a timer before you call handleLoginClick() again

function handleLoginClick():void
    {
        trace("connecting to facebook");
        if (FacebookMobile.getSession() == null)
        {
            FacebookMobile.init(APP_ID, onHandleInit, null);
            FacebookMobile.manageSession = false
        }
        else
        {
            var webView:StageWebView = new StageWebView();
            webView.viewPort = new Rectangle(0, 0, 1, 1);           
            webView.stage = this.stage;         
            webView.loadURL("https://m.facebook.com/logout.php?confirm=1&next=http://www.facebook.com&access_token=" + FacebookMobile.getSession().accessToken);
            webView.addEventListener(Event.COMPLETE,webviewhandleLoad);
            function webviewhandleLoad(e:Event)
            {
                FacebookMobile.logout(null, "http://apps.facebook.com/<appName>/");
                FacebookMobile.logout(null, "http://www.facebook.com");
                webView.dispose()
                webView = null
                setTimeout(handleLoginClick,3000)

            }
        }
    }
查看更多
贪生不怕死
3楼-- · 2019-02-24 19:58

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!")
}
查看更多
霸刀☆藐视天下
4楼-- · 2019-02-24 20:01

look at the solution of this problem. Maby someone it helps:

var stage_ref:Stage =  PlatformUtil.originalStage(); //my custom class to get stage
var webView:StageWebView = new StageWebView();
webView.viewPort = new Rectangle(0, 0, stage_ref.width, stage_ref.height);
FacebookMobile.login(loginCallback, stage_ref, appPermissions, webView);

http://code.google.com/p/facebook-actionscript-api/issues/detail?id=381

http://code.google.com/p/facebook-actionscript-api/issues/detail?id=382

http://code.google.com/p/facebook-actionscript-api/issues/detail?id=383

查看更多
▲ chillily
5楼-- · 2019-02-24 20:03

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.

查看更多
登录 后发表回答