Irfan
Irfan

Reputation: 2771

Twitter4J AccessToken Generation

I am trying to create instance of AccessToken but its raising exception message. I have two ways to generate the AccessToken. My workflow is that on android machine I authenticate the user using Oauth and then I get the accessKey, and accessSecret. I transfer those two strings to server using REST. I do following on server to get back AccessToken.

AccessToken token = new AccessToken(accessToken, accessSecret);

But above code is generating exeption that "java.lang.IllegalArgumentException: Invalid access token format." When I do the following:

twitter = new TwitterFactory().getInstance(); 
twitter.setOAuthConsumer(CONSUMER_KEY, CONSUMER_SECRET); 
AccessToken aToken = twitter.getOAuthAccessToken(accessToken, accessSecret);

It gives following twitter exception:

The screen name / password combination seems to be invalid.Relevant discussions can be on the Internet at:......

Finally, I also used following code:

ConfigurationBuilder cb = new ConfigurationBuilder(); 
cb.setDebugEnabled(true) .setOAuthConsumerKey(twitterKey)
.setOAuthConsumerSecret(twitterSecret) 
.setOAuthAccessToken(twitter.getAccessToken())
.setOAuthAccessTokenSecret(twitter.getSecretToken()); 
TwitterFactory tf = new TwitterFactory(cb.build()); 
twitter4j.Twitter t4jTwitter = tf.getInstance();

It gives same invalid format exception.

So my question is that "is this a potential bug??" and Can I create AccessToken instance when I already have accessKey and accessSecret strings??

Thank you very much for the prompt reply.

Irfan Mirza

Upvotes: 3

Views: 2661

Answers (1)

mvmn
mvmn

Reputation: 4067

Are you sure accessToken and accessSecret contain OK values? It really could be caused by some omission that would make those empty or something.

Upvotes: 1

Related Questions