简体   繁体   English

以编程方式清除Android上的Facebook SDK 4.0会话

[英]Programmatically clear Facebook SDK 4.0 session on Android

I integrated Facebook login into my app, and It works fine. 我将Facebook登录集成到我的应用程序中,它运行正常。 The issue is with the logout. 问题在于注销。

When I open the Facebook app on my device, I can perform a logout, so that the next time I open It, It will ask my If I want to login with my usual account, login with another account or even create a new account. 当我在设备上打开Facebook应用程序时,我可以执行注销,以便下次打开它时,它会询问我如果我想使用我的常用帐户登录,使用其他帐户登录,甚至创建新帐户。 Good, that is expected. 好,这是预期的。

But this doesn't happen with my app. 但我的应用程序不会发生这种情况。 I mean, If the user opens my app, clicks in "logout" and the code below is ran 我的意思是,如果用户打开我的应用程序,请单击“注销”并运行以下代码

// Initialize Facebook SDK on the beginning.
FacebookSdk.sdkInitialize(this.getApplicationContext());
...
// Logout on user choice.
LoginManager.getInstance().logOut();

the next time he is back on the app and clicks to login he will be logged in directly with his account, he won't be asked with each account he wants to login. 下次他回到应用程序并点击登录时,他将直接使用他的帐户登录,不会询问他想要登录的每个帐户。

I image that I need to clear all informations (tokens?) that are saved, which are being used into this directly login. 我想我需要清除所有保存的信息(令牌?),这些信息被用于直接登录。 Is this correct? 它是否正确? If yes, how can I do it? 如果是,我该怎么办?

Thank you, 谢谢,

I am using this method. 我正在使用这种方法。 It's for SDK 4.6.0, but I guess it should be the same as 4.0. 这是SDK 4.6.0,但我想它应该与4.0相同。 If not, just upgrade ;) 如果没有,只需升级;)

public void logoutFromFacebook(final LogoutFacebookListener listener) {

        if (AccessToken.getCurrentAccessToken() == null) {
            // already logged out
            listener.onLoggedOutFromFacebook();
            return;
        }

        new GraphRequest(AccessToken.getCurrentAccessToken(), "/me/permissions/", null, HttpMethod.DELETE, new GraphRequest
                .Callback() {

            @Override
            public void onCompleted(GraphResponse graphResponse) {

                LoginManager.getInstance().logOut();
                listener.onLoggedOutFromFacebook();
            }
        }).executeAsync();
    }

Listener: 监听器:

public interface LogoutFromFacebookListener {

    void onLoggedOutFromFacebook();
}

It seams like when you trying to login, facebook sdk uses your web browser (chrome, etc) in your case. 它就像你试图登录时一样,facebook sdk在你的情况下使用你的网络浏览器(chrome等)。 And when you call LoginManager.getInstance().logOut(); 当你调用LoginManager.getInstance().logOut(); you do logout just from facebook sdk, but you are still staying loggedin in your web browser. 你只是从facebook sdk注销,但你仍然在你的网络浏览器中登录。 The Android and iOS SDKs don't currently support re-authentication. Android和iOS SDK目前不支持重新身份验证。 Hope they will be in future ;) 希望他们将来会出现;)

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

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