Android - Clear Facebook access token

僤鯓⒐⒋嵵緔 提交于 2019-12-01 12:08:48

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());
Khaled Saif

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.

Do like this

try {
Session.getActiveSession().closeAndClearTokenInformation();
} catch (Throwable e) {
e.printStackTrace();
}
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();    
}
}

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...

Harish Godara

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!