2

This is what I'm getting while calling twitter.getOauthRequestToken(callbackUrl). I've added the correct consumer key and consumer secret.

    401:Authentication credentials (https://dev.twitter.com/docs/auth) were missing or incorrect. Ensure that you have set valid conumer key/secret, access token/secret, and the system clock in in sync.
<?xml version="1.0" encoding="UTF-8"?>
<hash>
  <error>Desktop applications only support the oauth_callback value 'oob'</error>
  <request>/oauth/request_token</request>
</hash>

I debugged the code multiple times and found every credentials in place before above call is made. Anyone who has used twitter4j or not can please indicate the problem? Or should I use another oauth library? Any suggestions?

Shwetanka
  • 4,976
  • 11
  • 44
  • 68

3 Answers3

9

i have same problem, but when i fill the field of callback URL my apps run normally. maybe you should fill the field of Callback URL.

Ari Pratomo
  • 1,195
  • 12
  • 8
2

I guess you registered your app as a "desktop" app. Go to twitter applications and either delete the app and create a new one or edit the existing one with "web" as the app type.

Nischal
  • 958
  • 2
  • 10
  • 14
  • 5
    There is a [quirk in the registration](http://groups.google.com/group/twitter-development-talk/browse_thread/thread/0f744fe83fd9ef90) that requires a callback URL in the registration page or it defaults you to a desktop app. – Mark S. Aug 22 '11 at 21:11
  • @Nischal, I have a similar question http://stackoverflow.com/questions/15326040/twitter4j-getting-inconcistent-authentication-errors, would love to get your thoughts. – user1172468 Mar 10 '13 at 18:54
2

Try this:

Twitter twitter = new TwitterFactory().getInstance();
twitter.setOAuthConsumer("yourConsumerKey","yourConsumerSecret");
RequestToken requestToken = twitter.getOAuthRequestToken();

session.setAttribute("token", requestToken.getToken());
session.setAttribute("tokenSecret", requestToken.getTokenSecret());

// REDIRECT USER TO TWITTER LOGIN PAGE

response.sendRedirect(requestToken.getAuthorizationURL());

CALLBACK URL PAGE CODE:

Twitter twitter = new TwitterFactory().getInstance();
twitter.setOAuthConsumer("yourConsumerKey","yourConsumerSecret");

AccessToken aToken = twitter.getOAuthAccessToken(new RequestToken((String) session.getAttribute("token"), (String) session.getAttribute("tokenSecret")));
                twitter.setOAuthAccessToken(aToken);