简体   繁体   中英

Twitter4j, how do i logout?

I was able to login and post with this twitter but I do not know how to log out.

I just pretend that I have logged out by adding

CookieManager cookieManager = CookieManager.getInstance();
    cookieManager.removeSessionCookie();

private boolean mCanTweet = false;

I tried logging out with this url that was in a tutorial but it's not working.

public static final String TWITTER_LOGOUT_URL = "https://api.twitter.com/logout";

Does anyone know how to do an "actual" logout with Twitter4j?

here is my project

http://dl.dropbox.com/u/12439052/stackoverflow/TwitterCon2.zip

I faced the same problem with my twitter4j project. I solved this by using this code

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

mTwitter.setOAuthAccessToken(null);
mTwitter.shutdown();

in the logout method, before re-loading the authentification activity.

From the author of Twitter4J who is Yusuke Yamamoto: "Twitter4J is authenticated by the API in stateless fashion using Basic auth header. It's totally stateless and logging out is not required."

https://groups.google.com/forum/?fromgroups=#!topic/twitter4j/WVdyLVluJpw

The concept of logout from twitter is just remove login information and you are signed out. Since when you tweet or do something with twitter from your app, it requires token etc, so you just need to delete them. I was facing the same problem for my android app, so after googling, i found simple solution. ie delete info. So i cleared my

SharedPrefferences

and done.!

Simplest way is to clear cookie .

write following one line code in your onCreate of webview class.

android.webkit.CookieManager.getInstance().removeAllCookie();

Hope it helps.

Twitter4J doesn't require a login at all, it performs a stateless request to the Twitter API. So You don't need to logout too.
Reference: https://groups.google.com/forum/?fromgroups#!topic/twitter4j/WVdyLVluJpw

Even if twitter4j is a stateless api, you can clear the credential using the following method

    private void clearCredentials() {
    final Editor edit = prefs.edit();
    edit.remove(OAuth.OAUTH_TOKEN);
    edit.remove(OAuth.OAUTH_TOKEN_SECRET);
    edit.commit();
    TwitterFactory().getInstance().shutdown();
}
CookieManager cookieManager = CookieManager.getInstance();
cookieManager.removeSessionCookie();
TwitterSession.resetAccessToken();
Twitter_Handler.twitterObj.shutdown();

Here make public static variables to twitterObj in handler and resetAccessToken in TwitterSession file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM