Logout from twitter when logout from my application


#1

Hello all,

I have use twitter login in my application, I want that when i logout from my application then also logout from twitter account also, How to logout from twitter?
Please help me to logout from twitter also.

Thanks
Mayur


#2

Not having this is a security problem


#3

u found ans ? if yes please tell me

i tried below code but not working at all

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

#4

This thread started over 3 years ago. Are you sure this is the same issue? Are you using Fabric and Twitter Kit?


#5

below code worked for me

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