Search code examples
androidtwitter4j

Twitter4j throws 'No authentication challenges found' after canceling login


I'm using Twitter4J for posting some tweets. When I try to post a tweet I open a webview with the authenticationURL to log in:

twitterRequestToken = twitter.getOAuthRequestToken(Constants.TWITTER_CALLBACK);

Intent i = new Intent(FutbolTvActivity.this, TwitterWebLoginActivity.class);
i.putExtra("URL", twitterRequestToken.getAuthenticationURL());
startActivityForResult(i, 1);

If I complete the process I get logged OK and can send the tweet. The problem is that if I click on cancel button on login web page and I try to login again I receive the next exception on

twitter.getOAuthRequestToken(Constants.TWITTER_CALLBACK): No authentication challenges found

If I reuse the previous authentication URL the webview shows an error message saying this URL is too old.

Can anyone help me?


Solution

  • Finally, I found a solution:

    At first time I was using:

    twitter = TwitterFactory.getSingleton()
    

    for getting the Twitter object. By this way the second time I call to getOAuthRequestToken() I get the error described above.

    No, I'm using:

    twitter = new TwitterFactory(configuration.build()).getInstance();
    

    so I have different instances every time I start the related activity. By this way, I never call a second time over the same instance to getOAuthRequestToken() so I have no errors.