【问题标题】:WooCommerce API - Getting JsonParseException when reading dataWooCommerce API - 读取数据时获取 JsonParseException
【发布时间】:2021-04-14 03:36:46
【问题描述】:

我正在编写一个程序来从 WordPress 页面获取订单。

在许多测试中,下一个代码正常工作:

        OAuthConfig config = new OAuthConfig(parameters.getUrl(), parameters.getConsumerKey(), parameters.getConsumerSecret());
        WooCommerce wooCommerce = new WooCommerceAPI(config, ApiVersionType.V3);

        Map<String, String> parametersOrders = new HashMap<>();
        parametersOrders .put("per_page", "100");
        parametersOrders .put("offset", "0");

        List ordersCreated = wooCommerce.getAll(EndpointBaseType.ORDERS.getValue(), parametersOrders );

但现在在生产中我遇到了下一个错误:

Caused by: com.fasterxml.jackson.core.JsonParseException: Unexpected character ('<' (code 60)): expected a valid value (number, String, array, object, 'true', 'false' or 'null') at [Source: org.apache.http.conn.EofSensorInputStream@56c43543; line: 1, column: 2]

显然,我正在读取 xml 对象而不是 json

我该如何改变呢?这是我缺少的东西?

提前谢谢...

编辑 1:

我第一次尝试这个,它工作正常:

https://stackoverflow.com/a/48968854/4815994

订单检索成功。现在我得到了错误。

【问题讨论】:

    标签: java woocommerce woocommerce-rest-api


    【解决方案1】:

    我跳过了参数部分;我正在从数据库中获取这些数据:

    WooCommerceParameters parameters= GetWooCommerceParameters();
    
    OAuthConfig config = new OAuthConfig(parameters.getUrl(), parameters.getConsumerKey(), parameters.getConsumerSecret());
    

    consumer key 和 consumer secret 都可以,但是 URL 格式如下:

    'https://test.com/store/'
    

    而且一定是这样的:

    'https://test.com/store'
    

    没有最后的斜线

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-03-08
      • 1970-01-01
      • 2022-01-25
      • 2021-06-12
      • 2017-09-27
      • 1970-01-01
      • 1970-01-01
      • 2020-11-17
      相关资源
      最近更新 更多