2013-07-12 65 views
0

我试图使用OAuth和路标使用我在开发论坛中看到的一个示例连接到Evernote,但由于某种原因,我一直收到错误代码400(错误的请求)。下面是代码:错误代码400使用Evernote OAuth(路标)

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 

我似乎可以用正确的程序在这里,但也许有所改变?我很感激帮助。

回答

0

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