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
Sorry.
I was setting an Access Token hard coded by the Configuration Builder.
Removed it, works now.
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();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With