signout using Twitter4J is not working with android

℡╲_俬逩灬. 提交于 2020-01-16 18:56:12

问题


I am using twitter 4j 3.0.2 jar I have integrate twitter in my android app.I have successfully login and send tweet to twitter account but I face issue in logout from twitter account from my android app.

I implement this as same as twitter4j sample app and I have noticed that same issue also in twitter4j sample app.

Steps I have done

  1. When first time I click on login button from my app then login page of twitter opened. 2.I save token in SharedPreferences. 3.Convert login button to logout. 4.Now I clicked on logout button and clear token from shared preferences. 5.Convert logout button to login 6.Again Click on login then login page of twitter should be opened rather than authorize app page be opened.

My main issue is that how to signout from twitter from android app.Is twitter cache is maintained in anywhere in device ? if yes then how I clear twitter cache from my android app.

Editor e = mSharedPreferences.edit();
        e.remove(PREF_KEY_OAUTH_TOKEN);
        e.remove(PREF_KEY_OAUTH_SECRET);
        e.remove(PREF_KEY_TWITTER_LOGIN);
        e.commit();
        //twitter.shutdown();
        twitter = new TwitterFactory().getInstance();
        twitter.setOAuthConsumer(TWITTER_CONSUMER_KEY,TWITTER_CONSUMER_SECRET);

回答1:


You need to use force login in twitter. For more details see my previous post

Twitter Login Dialog error

So you just need to add force_login=true in your authorize url i.e

http://twitter.com/oauth/authorize?force_login=true



回答2:


The simplest way is to clear the cookies.

Write the following one line code in your onCreate of the webview class.

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

Hope it helps.

Above code will remove all your cookie(like twitter,facebook and any other)

To signout from twitter you need to set the twitter oauth cookie to null.

CookieManager.getInstance().setCookie(".twitter.com", "auth_token=''");




回答3:


I solved issue just changing Call back url from oauth://t4jsample to... public static final String TWITTER_CALLBACK_URL = "api.twitter.com/oauth/authorize?force_login=true";



来源:https://stackoverflow.com/questions/16581232/signout-using-twitter4j-is-not-working-with-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!