Android - Clear Facebook access token

后端 未结 6 743
隐瞒了意图╮
隐瞒了意图╮ 2021-01-16 07:32

I have a SettingsActivity where there are several options including finding Facebook friends and logging out. So when a user chooses to find her Facebook friend

相关标签:
6条回答
  • 2021-01-16 08:18

    in Facebook SDK v4 we can log out using

    LoginManager.getInstance().logOut();
    

    note that don't forget to initialize sdk like this

    FacebookSdk.sdkInitialize(getApplicationContext());
    
    0 讨论(0)
  • 2021-01-16 08:19
    private Session.StatusCallback statusCallback = new SessionStatusCallback();
    
    logout.setOnClickListener(new OnClickListener() {
    @Override
    public void onClick(View arg0) {
    Session.openActiveSession(this, true, statusCallback);  
    }
    });
    
    private class SessionStatusCallback implements Session.StatusCallback {
    @Override
    public void call(Session session, SessionState state,
    Exception exception) {
    session.closeAndClearTokenInformation();    
    }
    }
    
    0 讨论(0)
  • 2021-01-16 08:19

    You should pass session variable through Parcelable interface and clear session through that session variable. Pass facebook session like this : Passing a Facebook session across activities

    0 讨论(0)
  • 2021-01-16 08:21

    Using Facebook SDK v4 you can do the following:

    if (AccessToken.getCurrentAccessToken() != null) {
        LoginManager.getInstance().logOut();
    }
    

    You can take a look at the LoginManager class.

    0 讨论(0)
  • 2021-01-16 08:25

    Do like this

    try {
    Session.getActiveSession().closeAndClearTokenInformation();
    } catch (Throwable e) {
    e.printStackTrace();
    }
    
    0 讨论(0)
  • 2021-01-16 08:36

    Try this below code for session clear in facebook integration android.

    Put below method in your activity and call before the login to facebook.

    public static void fbClearToken(Context context) {
        Session session = Session.getActiveSession();
        if (session != null) {
    
            if (!session.isClosed()) {
                session.closeAndClearTokenInformation();
                //clear your preferences if saved
            }
        } else {
            session = new Session(context);
            Session.setActiveSession(session);
    
            session.closeAndClearTokenInformation();
                //clear your preferences if saved
        }
    
    }
    

    For me it's working... Hope this is helpful for you...

    0 讨论(0)
提交回复
热议问题