1

我有一个使用 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>

参考:http: //twitter4j.org/en/code-examples.html

4

1 回答 1

0

您已将您的应用程序标记为“桌面应用程序”。您应使用应用程序设置将其更改为 Web 应用程序。

于 2013-08-12T20:09:10.673 回答