简体   繁体   English

Twitter4j,我该如何退出?

[英]Twitter4j, how do i logout?

I was able to login and post with this twitter but I do not know how to log out. 我能够使用此Twitter登录和发布,但我不知道如何注销。

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. 我尝试使用此教程中的URL注销,但它无法正常工作。

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

Does anyone know how to do an "actual" logout with Twitter4j? 有谁知道如何使用Twitter4j进行“实际”注销?

here is my project 这是我的项目

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

I faced the same problem with my twitter4j project. 我的twitter4j项目遇到了同样的问题。 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." 来自Twitter4J的作者Yusuke Yamamoto: “Twitter4J使用Basic auth header以无状态方式通过API进行身份验证。它完全没有状态,并且不需要注销。”

https://groups.google.com/forum/?fromgroups=#!topic/twitter4j/WVdyLVluJpw 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. 从twitter注销的概念只是删除登录信息,您已退出。 Since when you tweet or do something with twitter from your app, it requires token etc, so you just need to delete them. 因为当您从应用程序发送推文或使用Twitter做某事时,它需要令牌等,所以您只需要删除它们。 I was facing the same problem for my android app, so after googling, i found simple solution. 我的Android应用程序面临同样的问题,所以在谷歌搜索后,我找到了简单的解决方案。 ie delete info. 即删除信息。 So i cleared my 所以我清除了我的

SharedPrefferences

and done.! 并做了。!

Simplest way is to clear cookie . 最简单的方法是清除cookie。

write following one line code in your onCreate of webview class. 在webview类的onCreate中写下一行代码。

android.webkit.CookieManager.getInstance().removeAllCookie(); 。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. Twitter4J根本不需要登录,它会对Twitter API执行无状态请求。 So You don't need to logout too. 所以你也不需要注销。
Reference: https://groups.google.com/forum/?fromgroups#!topic/twitter4j/WVdyLVluJpw 参考: 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 即使twitter4j是无状态api,您也可以使用以下方法清除凭据

    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. 这里将公共静态变量设置为处理程序中的twitterObj和TwitterSession文件中的resetAccessToken。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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