在Java中使用WP-restapi

在Java中使用WP-restapi,java,wordpress,oauth,Java,Wordpress,Oauth,我试图在JavaSwing应用程序中使用插件“WpRESTAPI-OAuth1.0a服务器”从wordpress中使用OAuth1.0a 按照使用PostMan的此链接()的说明,它可以工作 我尝试在Java中用这段代码做同样的事情,但它不起作用,我不明白为什么 OAuthConsumer oAuthConsumer = new CommonsHttpOAuthConsumer(client_id, client_secret); HttpClient httpClient =

我试图在JavaSwing应用程序中使用插件“WpRESTAPI-OAuth1.0a服务器”从wordpress中使用OAuth1.0a

按照使用PostMan的此链接()的说明,它可以工作

我尝试在Java中用这段代码做同样的事情,但它不起作用,我不明白为什么

    OAuthConsumer oAuthConsumer = new CommonsHttpOAuthConsumer(client_id, client_secret);
    HttpClient httpClient = HttpClientBuilder.create().build();
    String urlRequest = jsonObjectAuth.getJSONObject("oauth1").getString("request");
    String urlAuthorize = jsonObjectAuth.getJSONObject("oauth1").getString("authorize");
    String urlAccess = jsonObjectAuth.getJSONObject("oauth1").getString("access");

    /*
    *
    *   Step 1
    *
    * */

    urlRequest = oAuthConsumer.sign(urlRequest);
    System.out.print("\nURLRequest: " + urlRequest);
    HttpGet httpGetRequest = new HttpGet(urlRequest);

    //oAuthConsumer.sign(httpGetRequest);

    HttpResponse httpResponseRequest = httpClient.execute(httpGetRequest);
    int codigoRespuesta = httpResponseRequest.getStatusLine().getStatusCode();

    String responseRequestString = null;

    if (codigoRespuesta == 200) {
        responseRequestString = new BasicResponseHandler().handleResponse(httpResponseRequest);
        System.out.print("\n" + responseRequestString);
    } else {
        System.out.print("\nRequest: " + httpResponseRequest.getStatusLine().toString());
        return;
    }

    /*
    *
    *   Step 2
    *
    * */

    urlAuthorize = urlAuthorize + "/?" +responseRequestString;
    System.out.print("\nURL para authorize: " + urlAuthorize);
    Desktop.getDesktop().browse(new URI(urlAuthorize));


    /*
    *
    *   Step 3
    *
    * */

    String oauth_verifier = JOptionPane.showInputDialog(jFrame, "Coloque aquí el token de verificación obtenido en el navegador","Token de verificación",JOptionPane.INFORMATION_MESSAGE);

    urlAccess = urlAccess + "/?" + responseRequestString + "&oauth_verifier=" + oauth_verifier;
    urlAccess = oAuthConsumer.sign(urlAccess);
    System.out.print("\nURLAccess: " + urlAccess);
当我打开生成的URLAccess时,我收到“OAuth签名不匹配”

我不明白为什么

    OAuthConsumer oAuthConsumer = new CommonsHttpOAuthConsumer(client_id, client_secret);
    HttpClient httpClient = HttpClientBuilder.create().build();
    String urlRequest = jsonObjectAuth.getJSONObject("oauth1").getString("request");
    String urlAuthorize = jsonObjectAuth.getJSONObject("oauth1").getString("authorize");
    String urlAccess = jsonObjectAuth.getJSONObject("oauth1").getString("access");

    /*
    *
    *   Step 1
    *
    * */

    urlRequest = oAuthConsumer.sign(urlRequest);
    System.out.print("\nURLRequest: " + urlRequest);
    HttpGet httpGetRequest = new HttpGet(urlRequest);

    //oAuthConsumer.sign(httpGetRequest);

    HttpResponse httpResponseRequest = httpClient.execute(httpGetRequest);
    int codigoRespuesta = httpResponseRequest.getStatusLine().getStatusCode();

    String responseRequestString = null;

    if (codigoRespuesta == 200) {
        responseRequestString = new BasicResponseHandler().handleResponse(httpResponseRequest);
        System.out.print("\n" + responseRequestString);
    } else {
        System.out.print("\nRequest: " + httpResponseRequest.getStatusLine().toString());
        return;
    }

    /*
    *
    *   Step 2
    *
    * */

    urlAuthorize = urlAuthorize + "/?" +responseRequestString;
    System.out.print("\nURL para authorize: " + urlAuthorize);
    Desktop.getDesktop().browse(new URI(urlAuthorize));


    /*
    *
    *   Step 3
    *
    * */

    String oauth_verifier = JOptionPane.showInputDialog(jFrame, "Coloque aquí el token de verificación obtenido en el navegador","Token de verificación",JOptionPane.INFORMATION_MESSAGE);

    urlAccess = urlAccess + "/?" + responseRequestString + "&oauth_verifier=" + oauth_verifier;
    urlAccess = oAuthConsumer.sign(urlAccess);
    System.out.print("\nURLAccess: " + urlAccess);

谢谢你的帮助。

邮递员与浏览器共享cookie,只做它的工作,我认为你的AUTH不能正常工作。可能值得考虑的库。