我有一个使用 JSF 的 Web 应用程序。
在我的页面上,我有一个按钮可以调用doTwitterLogin()
public void doTwitterLogin() {
try {
HttpServletRequest req = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
String url = req.getRequestURL().toString();
Twitter twitter = new TwitterFactory().getInstance();
twitter.setOAuthConsumer("xxx", "xxx");
RequestToken requestToken = twitter.getOAuthRequestToken(url);
FacesContext.getCurrentInstance().getExternalContext().getSessionMap().put("requestToken_token", requestToken.getToken());
FacesContext.getCurrentInstance().getExternalContext().getSessionMap().put("requestToken_secret", requestToken.getTokenSecret());
FacesContext.getCurrentInstance().getExternalContext().redirect(requestToken.getAuthorizationURL());
} catch (Exception e) {
e.printStackTrace();
}
}
部分调试后出现异常RequestToken requestToken = twitter.getOAuthRequestToken(url);
。
SEVERE: 401:Authentication credentials (https://dev.twitter.com/pages/auth) were missing or incorrect. Ensure that you have set valid consumer key/secret, access token/secret, and the system clock is 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>