Problem in Oauth with twitter4j

醉酒当歌 提交于 2019-12-06 08:42:37

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.

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.

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