如何以编程方式从Facebook SDK 3.0注销无需使用Facebook登录/注销按钮? [英] How to programmatically log out from Facebook SDK 3.0 without using Facebook login/logout button?

查看:199
本文介绍了如何以编程方式从Facebook SDK 3.0注销无需使用Facebook登录/注销按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

标题说明了一切。我使用的是自定义按钮来获取用户的Facebook信息(注册的目的)。不过,我不希望该应用还记得上注册的用户,无论是通过Facebook的本机应用程序当前登录的人。我想Facebook登录活动每次都弹出。这就是为什么我要pvious用户编程登录任何$ P $。

The title says it all. I'm using a custom button to fetch the user's facebook information (for "sign up" purposes). Yet, I don't want the app to remember the last registered user, neither the currently logged in person via the Facebook native app. I want the Facebook login activity to pop up each time. That is why I want to log out any previous users programmatically.

我怎么能这样做?这是我做的登录:

How can I do that? This is how I do the login:

private void signInWithFacebook() {

    SessionTracker sessionTracker = new SessionTracker(getBaseContext(), new StatusCallback() 
    {
        @Override
        public void call(Session session, SessionState state, Exception exception) { 
        }
    }, null, false);

    String applicationId = Utility.getMetadataApplicationId(getBaseContext());
    mCurrentSession = sessionTracker.getSession();

    if (mCurrentSession == null || mCurrentSession.getState().isClosed()) {
        sessionTracker.setSession(null);
        Session session = new Session.Builder(getBaseContext()).setApplicationId(applicationId).build();
        Session.setActiveSession(session);
        mCurrentSession = session;
    }

    if (!mCurrentSession.isOpened()) {
        Session.OpenRequest openRequest = null;
        openRequest = new Session.OpenRequest(RegisterActivity.this);

        if (openRequest != null) {
            openRequest.setPermissions(null);
            openRequest.setLoginBehavior(SessionLoginBehavior.SSO_WITH_FALLBACK);

            mCurrentSession.openForRead(openRequest);
        }
    }else {
        Request.executeMeRequestAsync(mCurrentSession, new Request.GraphUserCallback() {
              @Override
              public void onCompleted(GraphUser user, Response response) {
                  fillProfileWithFacebook( user );
              }
            });
    }
}

在理想情况下,我会打个电话,在此方法的开头注销任何previous用户。

Ideally, I would make a call at the beginning of this method to log out any previous users.

推荐答案

更新为最新的SDK:

现在@ zeuter的答案是正确的Facebook SDK V4.7 +:

Now @zeuter's answer is correct for Facebook SDK v4.7+:

LoginManager.getInstance()退出();

原来的答复:

请不要使用SessionTracker。它是一个内部(包专用)类,并且不意味着被消耗作为公共API的一部分。因此,它的API可随时更改,恕不任何向后兼容的保证。你应该能够在你的code摆脱SessionTracker的所有实例,而只是使用活动会话吧。

Please do not use SessionTracker. It is an internal (package private) class, and is not meant to be consumed as part of the public API. As such, its API may change at any time without any backwards compatibility guarantees. You should be able to get rid of all instances of SessionTracker in your code, and just use the active session instead.

要回答你的问题,如果你不想让任何会话数据,只需调用<一href="https://developers.facebook.com/docs/reference/android/3.0/Session#closeAndClearTokenInformation%28%29">closeAndClearTokenInformation当你的应用程序关闭。

To answer your question, if you don't want to keep any session data, simply call closeAndClearTokenInformation when your app closes.

这篇关于如何以编程方式从Facebook SDK 3.0注销无需使用Facebook登录/注销按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆