How do I log out of my Twitter account by deleting cookies?

I want to sign out of my Twitter account by deleting the cookies she created. I can extract the cookies created by twitter using the code:

String twit_cookie = getCookie ("http://www.twitter.com"); 

But how can I delete only cookies created by twitter, because removeAllCookie () deletes all cookies created by the browser. How can I delete a specific cookie by URL or by name ???

Please, help...

+7
source share
2 answers

The CookieManager class has a setCookie method. Have you tried this like:

 setCookie("http://www.twitter.com", null); 

Or maybe

 setCookie("http://www.twitter.com", "auth_token=''"); 
+3
source

You can use the CookieManager # setCookie (String url, String value) method. As stated in the docs:

Sets a cookie for this URL. Any existing cookie with the same host, path and name will be replaced with a new cookie.

The β€œclearest” way is to set all the cookies created by Twitter have expired (past time). The code from this answer is almost right, except for a future date.
Modified Code:

 final String domain = "http://www.twitter.com"; CookieSyncManager.createInstance(this); CookieManager cookieManager = CookieManager.getInstance(); String cookiestring = cookieManager.getCookie(domain); //get all cookies String[] cookies = cookiestring.split(";"); for (int i=0; i<cookies.length; i++) { String[] cookieparts = cookies[i].split("="); //split cookie into name and value etc. // set cookie to an expired date cookieManager.setCookie(domain, cookieparts[0].trim()+"=; Expires=Wed, 31 Dec 2000 23:59:59 GMT"); } CookieSyncManager.getInstance().sync(); //sync the new cookies just to be sure 
+3
source

All Articles