Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to logout from twitter using Fabric Sdk for android

I used

Twitter.getSessionManager().clearActiveSession();

This does not work,next time when i logIn using twitter, it opens the dialog with browser,takes previous login and just asks "Allow app to fetch your data?", but doesn't ask for username and password.Any help will be appreciated.

like image 367
Neal Ahluvalia Avatar asked Apr 20 '15 09:04

Neal Ahluvalia


2 Answers

I finally found a solution to this situation.

Accidentally, I found a method in Twitter SDK Kit for Android

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

This was very simple, it took me about half an hour to find it.

For version 3.0 and above

CookieSyncManager.createInstance(this);
CookieManager cookieManager = CookieManager.getInstance();
cookieManager.removeSessionCookie();
TwitterCore.getInstance().getSessionManager().clearActiveSession()
like image 66
Neal Ahluvalia Avatar answered Sep 30 '22 18:09

Neal Ahluvalia


Now that CookieSyncManager is deprecated, I do it this way:

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();
        }
    }
like image 22
Mohit Singh Avatar answered Sep 30 '22 17:09

Mohit Singh