我试图通过邮递员使用wc-api / v1和wc-api / v2并且它们不起作用。只有wc-api / v3可以正常使用我的网站。但是当我尝试使用java库wc-api-java 1.2(https://github.com/icoderman/wc-api-java):
时OAuthConfig config = new OAuthConfig(
"http://URL",
"ck_XXX",
"cs_XXX"
);
WooCommerce wooCommerce = new WooCommerceAPI(config, ApiVersionType.V2);
// Prepare object for request
Map<String, Object> productInfo = new HashMap<String, Object>();
productInfo.put("name", "Premium Quality");
productInfo.put("type", "simple");
productInfo.put("regular_price", "21.99");
productInfo.put("description", "This field contains description info.");
//Make request and retrieve result
Map product = wooCommerce.create(EndpointBaseType.PRODUCTS.getValue(), productInfo);
System.out.println(product.get("id"));
// Get all with request parameters
Map<String, String> params = new HashMap<String, String>();
params.put("per_page","100");
params.put("offset","0");
List products = wooCommerce.getAll(EndpointBaseType.PRODUCTS.getValue(), params);
System.out.println(products.size());
有一个例外:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/http/client/methods/HttpRequestBase
at com.icoderman.woocommerce.WooCommerceAPI.<init>(WooCommerceAPI.java:21)
at Main.main(Main.java:21)
Caused by: java.lang.ClassNotFoundException: org.apache.http.client.methods.HttpRequestBase
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
哪里无法使用wc-api / v3?
答案 0 :(得分:0)
问题出在没有http客户端的情况下。解决了使用maven添加apache httpclient依赖关系:
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.5</version>
</dependency>