Oauth problem with twitter4j

This is what I get when called twitter.getOauthRequestToken(callbackUrl). I 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 several times and found that all the credentials were in place before making the call. Anyone who used twitter4j or not can point out the problem? Or should I use another oauth library? Any suggestions?

+2
source share
3 answers

I assume that you registered your application as a โ€œdesktopโ€ application. Go to twitter applications and either delete the application, or create a new one, or edit the existing one using the "web" as the type of application.

+2
source

, , . , URL .

+9

Try the following:

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);
+2
source

All Articles