使用twitter4j在Oauth中出现问题

这是我在调用twitter.getOauthRequestToken(callbackUrl) 。 我添加了正确的消费者密钥和消费者秘密。

  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.   Desktop applications only support the oauth_callback value 'oob' /oauth/request_token  

我多次调试代码,并在上面调用之前找到了所有凭据。 任何使用过twitter4j的人都能指出问题吗? 或者我应该使用另一个oauth库? 有什么建议么?

我猜您将应用注册为“桌面”应用。 转到Twitter应用程序,删除应用程序并创建一个新应用程序,或者使用“web”作为应用程序类型编辑现有应用程序。

我有同样的问题,但当我填写回调URL字段时,我的应用程序正常运行。 也许你应该填写回调url的字段。

尝试这个:

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