Skip to content

Some questions about WP API V2 Client #55

@hasanli-orkhan

Description

@hasanli-orkhan

Hello!
First of all, thank you so much for this java client.
I have some questions and because of the lack of documentation I would like to clarify them with you. Hope you take some time with me. Thank you in advance!
Is client version 4.13.x working?
I have builded jar in Intellij IDEA ( empty jar or jar from modules with dependencies) and try the snippet below I get another exception:

16:38:05.860 [main] ERROR c.a.w.wpapi.v2.util.MavenProperties - Error loading properties 
java.lang.NullPointerException: null
	at java.util.Properties$LineReader.readLine(Properties.java:434) ~[na:1.8.0_191]
	at java.util.Properties.load0(Properties.java:353) ~[na:1.8.0_191]
	at java.util.Properties.load(Properties.java:341) ~[na:1.8.0_191]
	at com.afrozaar.wordpress.wpapi.v2.util.MavenProperties.getProperties(MavenProperties.java:19) ~[wp-api-v2-client-java.jar:4.1.7.RELEASE]
	at com.afrozaar.wordpress.wpapi.v2.Client.<init>(Client.java:90) [wp-api-v2-client-java.jar:4.1.7.RELEASE]
	at com.afrozaar.wordpress.wpapi.v2.Client.<init>(Client.java:95) [wp-api-v2-client-java.jar:4.1.7.RELEASE]
	at com.afrozaar.wordpress.wpapi.v2.config.ClientFactory.fromConfig(ClientFactory.java:12) [wp-api-v2-client-java.jar:4.1.7.RELEASE]
	at testt.test.main(test.java:22) [classes/:na]
16:38:06.604 [main] DEBUG c.afrozaar.wordpress.wpapi.v2.Client - Request Entity: <POST https://md7.info?rest_route=/wp/v2/posts,{author=[null], content=test, title=test, status=publish},{User-Agent=[null/null], Authorization=[Basic YWRtaW46Z2xvYmFsbmV0d29yazI0], Content-Type=[application/json]}>
com.afrozaar.wordpress.wpapi.v2.exception.PostCreateException: 400 Bad Request parameter: author
	at com.afrozaar.wordpress.wpapi.v2.Client.createPost(Client.java:146)
	at com.afrozaar.wordpress.wpapi.v2.Client.createPost(Client.java:152)
	at testt.test.main(test.java:35)
Caused by: org.springframework.web.client.HttpClientErrorException: 400 Bad Request
	at org.springframework.web.client.DefaultResponseErrorHandler.handleError(DefaultResponseErrorHandler.java:91)
	at org.springframework.web.client.RestTemplate.handleResponse(RestTemplate.java:614)
	at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:570)
	at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:545)
	at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:507)
	at com.afrozaar.wordpress.wpapi.v2.Client.doExchange0(Client.java:1007)
	at com.afrozaar.wordpress.wpapi.v2.Client.doExchange0(Client.java:1013)
	at com.afrozaar.wordpress.wpapi.v2.Client.doExchange1(Client.java:1034)
	at com.afrozaar.wordpress.wpapi.v2.Client.createPost(Client.java:144)
	... 2 more

Snippet which I used to test the client:

public class test {
  public static void main(String[] args) {
    String url = "https://example.com";
    String login = "admin";
    String password = "12345";
    final Wordpress client = ClientFactory.fromConfig(ClientConfig.of(
            url, login, password, false, true
    ));
    String articleTitle = "test";
    String articleContent = "test";
    final Post post = PostBuilder.aPost()
            .withTitle(TitleBuilder.aTitle().withRendered(articleTitle).build())
            .withContent(ContentBuilder.aContent().withRendered(articleContent).build())
            .build();
    try {
      final Post createdPost = client.createPost(post, PostStatus.publish);
    } catch (PostCreateException e) {
      e.printStackTrace();
    }

  }
}

P.S. When I use this snippet with the client version 4.8.3 (from mvnrepository) It works well. Link

Links to builded jar:
https://send.firefox.com/download/6b87ae513fe90145/#4A71Xr6QLSwcQunFT-qTpw

P.P.S. And what about JWT authentication?
Thanks again!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions