簡體   English   中英

如何使用Fabric Sdk從android注銷

[英]How to logout from twitter using Fabric Sdk for android

我用了

Twitter.getSessionManager().clearActiveSession();

這不起作用,下次當我使用twitter登錄時,它會打開瀏覽器的對話框,需要先前登錄,然后詢問“允許應用程序獲取您的數據?”,但不要求輸入用戶名和密碼。任何幫助都將是贊賞。

我終於找到了解決這種情況的方法。

無意中,我在Twitter SDK Kit for Android中找到了一種方法

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

這很簡單,我花了大約半個小時才找到它。

對於3.0及更高版本

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();
    }
}

上述方法已經滅絕。

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

您現在可以使用:

Digits.logout();
TwitterCore.getInstance().getSessionManager().clearActiveSession();

當您使用Twitter Auth登錄時,這是logout方法

要注銷當前用戶,只需致電

mTwitter.shutdown();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM