Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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
@lorensiuswlt authored
Showing with 8 additions and 2 deletions.
  1. +3 −1 README
  2. +5 −1 src/net/londatiga/android/TwitterApp.java
View
4 README
@@ -6,4 +6,6 @@ Website: http://www.londatiga.net
This is a sample Android project to show how to post twitter status from Android. Feel free to use it ;)
-Regards
+Changes 2011-10-01
+------------------
+- Fix authorization failed bug when trying to authorize after logging out (java.lang.IllegalStateException: consumer key/secret pair already set)
View
6 src/net/londatiga/android/TwitterApp.java
@@ -40,6 +40,7 @@
private ProgressDialog mProgressDlg;
private TwDialogListener mListener;
private Context context;
+ private boolean mInit = true;
public static final String CALLBACK_URL = "twitterapp://connect";
private static final String TAG = "TwitterApp";
@@ -73,7 +74,10 @@ public void setListener(TwDialogListener listener) {
@SuppressWarnings("deprecation")
private void configureToken() {
if (mAccessToken != null) {
- mTwitter.setOAuthConsumer(mConsumerKey, mSecretKey);
+ if (mInit) {
+ mTwitter.setOAuthConsumer(mConsumerKey, mSecretKey);
+ mInit = false;
+ }
mTwitter.setOAuthAccessToken(mAccessToken);
}

5 comments on commit 07df743

@sktest2

After that change also same problem exists.

@ZuliadyAzwin

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);
}
@lorensiuswlt

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.