5

I am receiving error messages while working with Twitter4J:

java.lang.IllegalStateException: Access token already available.
twitter4j.auth.OAuthAuthorization.getOAuthRequestToken(OAuthAuthorization.java:112)
twitter4j.auth.OAuthAuthorization.getOAuthRequestToken(OAuthAuthorization.java:104)
twitter4j.TwitterBaseImpl.getOAuthRequestToken(TwitterBaseImpl.java:276)
twitter4j.TwitterBaseImpl.getOAuthRequestToken(TwitterBaseImpl.java:269)
[...]

This exception is thrown while calling the method Twitter.getOAuthRequestToken(). I want to get the Authorization URL to authenticate the next user.

How am I possible to solve this problem? I only put the OAuthConsumerKey, the OAuthConsumerSecret, the OAuthAccessToken and the OAuthAccessTokenSecret to the Twitter4J properties. But how do I receive the authorization URL to authenticate a new user?

Thanks and greetings,

Martin

Martin Bories
  • 1,067
  • 17
  • 37

2 Answers2

10

Sorry.

I was setting an Access Token hard coded by the Configuration Builder.

Removed it, works now.

Martin Bories
  • 1,067
  • 17
  • 37
8

You need to create a new instance of twitter and null it's accessToken and accessTokenSecret fields before requesting new access token.

ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.setDebugEnabled(true)
            .setOAuthConsumerKey(TWITTER_CONSUMER_KEY)
            .setOAuthConsumerSecret(TWITTER_CONSUMER_SECRET)
            .setOAuthAccessToken(null)
            .setOAuthAccessTokenSecret(null);
    TwitterFactory tf = new TwitterFactory(cb.build());
    Twitter twitter = tf.getInstance();
kezoo
  • 99
  • 1
  • 3