Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fix authorization failed bug when attempt to authorize after logging out

This was caused by an exception (java.lang.IllegalStateException:
consumer key/secret pair already set) was thrown by
setOauthConsumer(consumerKey,secretKey) method of Twitter class. This
method should be called once
  • Loading branch information...
commit 07df74365151d3cd9ec99af861a10fb61d2a5081 1 parent e4fa6ef
Lorensius W. L. T authored

Showing 2 changed files with 8 additions and 2 deletions. Show diff stats Hide diff stats

  1. +3 1 README
  2. +5 1 src/net/londatiga/android/TwitterApp.java
4 README
@@ -6,4 +6,6 @@ Website: http://www.londatiga.net
6 6
7 7 This is a sample Android project to show how to post twitter status from Android. Feel free to use it ;)
8 8
9   -Regards
  9 +Changes 2011-10-01
  10 +------------------
  11 +- Fix authorization failed bug when trying to authorize after logging out (java.lang.IllegalStateException: consumer key/secret pair already set)
6 src/net/londatiga/android/TwitterApp.java
@@ -40,6 +40,7 @@
40 40 private ProgressDialog mProgressDlg;
41 41 private TwDialogListener mListener;
42 42 private Context context;
  43 + private boolean mInit = true;
43 44
44 45 public static final String CALLBACK_URL = "twitterapp://connect";
45 46 private static final String TAG = "TwitterApp";
@@ -73,7 +74,10 @@ public void setListener(TwDialogListener listener) {
73 74 @SuppressWarnings("deprecation")
74 75 private void configureToken() {
75 76 if (mAccessToken != null) {
76   - mTwitter.setOAuthConsumer(mConsumerKey, mSecretKey);
  77 + if (mInit) {
  78 + mTwitter.setOAuthConsumer(mConsumerKey, mSecretKey);
  79 + mInit = false;
  80 + }
77 81
78 82 mTwitter.setOAuthAccessToken(mAccessToken);
79 83 }

5 comments on commit 07df743

sktest2

After that change also same problem exists.

Zuliady Azwin

let see what we can do with this code :)

anticafe

Confirm. I got this error too.

SecretNick

Probably I have found a solution about this issue.
I think that the problem is the presences of old cookies in any new WebView call.

Try to use this code snippet in TwitterDialog.java:

private void setUpWebView() {
    mWebView = new WebView(getContext());

    // START MY NEW CODE
    CookieSyncManager.createInstance(getContext()); 
    CookieManager cookieManager = CookieManager.getInstance();
    cookieManager.removeAllCookie();
    // END MY NEW CODE

    mWebView.setVerticalScrollBarEnabled(false);
    mWebView.setHorizontalScrollBarEnabled(false);
    mWebView.setWebViewClient(new TwitterWebViewClient());
    mWebView.getSettings().setJavaScriptEnabled(true);
    mWebView.loadUrl(mUrl);
    mWebView.setLayoutParams(FILL);

    mContent.addView(mWebView);
}
Lorensius W. L. T
Owner

Hi thanks for the solution, yes..that was caused by browser's cookie...

Please sign in to comment.
Something went wrong with that request. Please try again.