Problem in Oauth with twitter4j

对着背影说爱祢 提交于 2019-12-10 10:48:40

问题


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?


回答1:


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.




回答2:


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.




回答3:


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);


来源:https://stackoverflow.com/questions/7152735/problem-in-oauth-with-twitter4j

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!