我正在尝试使用我在开发论坛中看到的示例之一通过 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
我似乎在这里使用了正确的程序,但也许有什么改变了?我很感激帮助。