android 如何使用 Fabric Sdk 从 Twitter 注销

How to logout from twitter using Fabric Sdk for android

我用了

Twitter.getSessionManager().clearActiveSession();

这不起作用,下次我使用 Twitter 登录时,它会打开带有浏览器的对话框,使用之前的登录并只询问 "Allow app to fetch your data?",但不询问用户名和 password.Any帮助将不胜感激。

我终于找到了解决这种情况的方法。

无意间在Twitter SDK Kit中找到了一个方法Android

CookieSyncManager.createInstance(this);
CookieManager cookieManager = CookieManager.getInstance();
cookieManager.removeSessionCookie();
Twitter.getSessionManager().clearActiveSession();
Twitter.logOut();

这个很简单,找了大概半个小时

For version 3.0 and above

CookieSyncManager.createInstance(this);
CookieManager cookieManager = CookieManager.getInstance();
cookieManager.removeSessionCookie();
TwitterCore.getInstance().getSessionManager().clearActiveSession()

现在 CookieSyncManager 已被弃用,我这样做:

public void logoutTwitter() {
        TwitterSession twitterSession = TwitterCore.getInstance().getSessionManager().getActiveSession();
        if (twitterSession != null) {
            ClearCookies(getApplicationContext());
            Twitter.getSessionManager().clearActiveSession();
            Twitter.logOut();
        }
}

public static void ClearCookies(Context context) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
            CookieManager.getInstance().removeAllCookies(null);
            CookieManager.getInstance().flush();
        } else {
            CookieSyncManager cookieSyncMngr=CookieSyncManager.createInstance(context);
            cookieSyncMngr.startSync();
            CookieManager cookieManager=CookieManager.getInstance();
            cookieManager.removeAllCookie();
            cookieManager.removeSessionCookie();
            cookieSyncMngr.stopSync();
            cookieSyncMngr.sync();
        }
    }

最后一个可行的解决方案:

public static void logoutTwitter() {
    TwitterSession twitterSession = TwitterCore.getInstance().getSessionManager().getActiveSession();
    if (twitterSession != null) {
        clearTwitterCookies(mAppContext);
        Twitter.getSessionManager().clearActiveSession();
        Twitter.logOut();
    }
}

public static void clearTwitterCookies(Context context) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
        CookieManager.getInstance().removeAllCookies(null);
        CookieManager.getInstance().flush();

    } else {
        CookieSyncManager cookieSyncMngr = CookieSyncManager.createInstance(context);
        cookieSyncMngr.startSync();
        CookieManager cookieManager = CookieManager.getInstance();
        cookieManager.removeAllCookie();
        cookieManager.removeSessionCookie();
        cookieSyncMngr.stopSync();
        cookieSyncMngr.sync();
    }
}

您现在可以使用:

Digits.logout();

以上方法已绝迹

// twitter log out
TwitterCore.getInstance().getSessionManager().clearActiveSession();

注销当前用户只需调用

mTwitter.shutdown();
TwitterCore.getInstance().getSessionManager().clearActiveSession();

当您使用 Twitter Auth

登录时,这是 logout 方法