简体   繁体   English

Facebook退出无法运行Android [Facebook sdk 4]

[英]Facebook logout does not work Android [Facebook sdk 4]


I'm developing a game for Android that has Facebook login and I faced the following weird behaviour when trying to logout: 我正在开发一款具有Facebook登录功能的Android游戏,在尝试注销时遇到了以下奇怪的行为:
if user press Facebook logout button, closes the app and then reopens again, the user is still logged in (= access token still valid). 如果用户按下Facebook注销按钮,关闭应用程序然后再次重新打开,则用户仍然登录(=访问令牌仍然有效)。 As a test, I checked the access token after logout and it is null as it should be, but if I close and reopen the app then the access token is again not null. 作为测试,我在注销后检查了访问令牌,它应该是null,但如果我关闭并重新打开应用程序,那么访问令牌也不会为空。
It seems that Facebook caches the access token and takes it from cache even after logout. 似乎Facebook缓存访问令牌,即使在注销后也从缓存中获取。

I tried using native Facebook button and also LoginManager.getInstance.logout(); 我尝试使用本机Facebook按钮和LoginManager.getInstance.logout(); I have initialized Facebook sdk on the top of the onCreate, before setContent() and I followed the procedure on Facebook docs, but same result. 我已经在onCreate的顶部初始化了Facebook sdk,然后在setContent()之前,我按照Facebook文档上的程序,但结果相同。

I'm using Facebook sdk 4.6.0 and I faced this problem on Android 4.2.2 and 4.4.2. 我正在使用Facebook sdk 4.6.0,我在Android 4.2.2和4.4.2上遇到了这个问题。

EDIT 编辑

Here's the code: 这是代码:

- Facebook button: - Facebook按钮:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    FacebookSdk.sdkInitialize(getApplicationContext());
    setContentView(R.layout.activity_settings);
    btnFacebookLogout.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
        @Override
        public void onSuccess(LoginResult loginResult) {

        }

        @Override
        public void onCancel() {
        }

        @Override
        public void onError(FacebookException e) {

        }
    });
}



- normal button: - 普通按钮:

btnNormalLogout.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            LoginManager.getInstance().logOut();
        }
    });

Any suggestion? 有什么建议吗?

Thanks in advance 提前致谢

Well, i`ve been fighting that damn sdk for about an hour and discovered a simple workaround for that logout issue. 好吧,我已经和那个该死的sdk打了大约一个小时,并发现了一个简单的解决方案来解决这个问题。

Just try to do the following: LoginManager.getInstance().setLoginBehavior(LoginBehavior.WEB_ONLY) 只需尝试执行以下操作:LoginManager.getInstance()。setLoginBehavior(LoginBehavior.WEB_ONLY)

Pros: LoginManager.getInstance().logOut() works fine in this case. 优点:LoginManager.getInstance()。logOut()在这种情况下工作正常。

Cons: the authentication will always appear in a webview dialog. 缺点:身份验证将始终显示在Webview对话框中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM