Facebook动作脚本3 API登录/注销问题

时间:2011-11-19 23:45:24

标签: facebook actionscript-3 facebook-graph-api air

我正在使用Flash builder 4.5,AIR 2.6,Facebook action script 3 API the latest version为Android制作移动AIR应用。

登录/退出时遇到问题。我只能登录一次 - 然后我的数据以某种方式缓存,Facebook会自动登录。当我呼叫注销时,我收到响应TRUE,但我没有真正从系统注销。我没有出现标准登录对话框。我已经在官方网站上阅读了很多关于stackoverflow和open问题的文章,但是没有一篇文章有​​用。我怎么解决这个问题?这是我使用的代码:

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 个答案:

答案 0 :(得分:6)

您只是将logoutCallback的第一个参数传递给logout方法。如果您添加为您的应用指定的网站网址的第二个参数,则应将其清除为该窗口的html Cookie。另外,设置FacebookMobile.manageSession = false;

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

有一个潜在的相关错误,涉及桌面和移动设备无法以相同的方式访问或清除访问令牌。为此,有一个hack描述了在FacebookMobile中暴露访问令牌,然后用访问令牌手动调用“注销”方法。这里描述了该问题,包括一个名为“reallyLogout”的方法。 If what I've written above doesn't work, implement "reallyLogout".

当您退出时,您的应用会清除本地会话,但不会让您退出系统。这在the documentation for logout.中明确定义。如果您已登录,请考虑一下进入Facebook的智能手机,网络浏览器,现在这个移动桌面应用程序,突然你注销了...它不应该在任何地方,只是在浏览器会话中注销你。所以传递第二个参数。

答案 1 :(得分:1)

我遇到了这个问题,经过多次修复后,这似乎终于有效了:

默认注销功能似乎无法通过FacebookMobile动作脚本API正确清除Cookie。 comment #33 here中的解决方案为我工作,转载于此。请务必在您自己的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!")
}

答案 2 :(得分:1)

整天都有这个Android Facebook清理注销问题,设法解决它。希望能帮助到你。这是我的FB移动句柄登录代码,以确保删除所有fb cookie和会话,并且用户需要重新登录。
有时FB服务器很慢。在再次调用handleLoginClick()之前最好放一个计时器

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 :(得分:0)

看看这个问题的解决方案。 Maby有人帮忙:

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