错误代码400与Evernote OAuth(路标)

时间:2013-07-12 14:43:19

标签: java oauth evernote signpost

我正在尝试使用我在开发论坛中看到的示例之一使用OAuth和Signpost连接到Evernote,但由于某种原因,我不断收到错误代码400(错误请求)。这是代码:

public static void main(String[] args) throws Exception {
        // TODO Auto-generated method stub
        String consumerKey = "key_here";
        String consumerSecret = "secret_key_here";

        OAuthConsumer consumer = new DefaultOAuthConsumer(consumerKey,
                consumerSecret);
        consumer.setMessageSigner(new PlainTextMessageSigner());
        OAuthProvider provider = new DefaultOAuthProvider(
                "https://sandbox.evernote.com/oauth",
                "https://sandbox.evernote.com/oauth",
                "https://sandbox.evernote.com/OAuth.action") {
            private static final long serialVersionUID = 1L;

            @Override
            protected HttpRequest createRequest(String endpointUrl)
                    throws MalformedURLException, IOException {
                HttpURLConnection connection = (HttpURLConnection) new URL(
                        endpointUrl).openConnection();
                connection.setRequestMethod("GET");
                connection.setAllowUserInteraction(false);
                connection.setRequestProperty("Content-Length", "0");
                return new HttpURLConnectionRequestAdapter(connection);
            }
        };
        String authUrl = provider.retrieveRequestToken(consumer,
                OAuth.OUT_OF_BAND);
        System.out.println(authUrl);
    }

(在任何人问之前,是的,我确实用自己的密钥替换了占位符) 这是错误:

Exception in thread "main" oauth.signpost.exception.OAuthCommunicationException: Communication with the service provider failed: Service provider responded in error: 400 (Bad Request)
    at oauth.signpost.AbstractOAuthProvider.retrieveToken(AbstractOAuthProvider.java:218)
    at oauth.signpost.AbstractOAuthProvider.retrieveRequestToken(AbstractOAuthProvider.java:74)
    at com.zakta.evernote.module.EvernoteAuthenticationTest.main(EvernoteAuthenticationTest.java:44)
Caused by: oauth.signpost.exception.OAuthCommunicationException: Service provider responded in error: 400 (Bad Request)
    at oauth.signpost.AbstractOAuthProvider.handleUnexpectedResponse(AbstractOAuthProvider.java:245)
    at oauth.signpost.AbstractOAuthProvider.retrieveToken(AbstractOAuthProvider.java:193)
    ... 2 more

我似乎在这里使用了正确的程序,但也许有些事情发生了变化?我很感激帮助。

1 个答案:

答案 0 :(得分:0)

当前的Evernote OAuth不允许使用OUT_OF_BOUND。您需要传递回调网址。