我正在尝试使用Java编程语言的Woo Commerce API更新产品数量。
使用的依赖项:
<dependency>
<groupId>com.icoderman</groupId>
<artifactId>wc-api-java</artifactId>
<version>1.2</version>
</dependency>
Java代码如下:
OAuthConfig config = new OAuthConfig(
PropertyFileHandler.PROPERTY_OBJECT.getProperty("WOOCOMMERCE_BASE_URL"),
PropertyFileHandler.PROPERTY_OBJECT.getProperty("WOOCOMMERCE_CONSUMER_KEY"),
PropertyFileHandler.PROPERTY_OBJECT.getProperty("WOOCOMMERCE_SECRET_KEY"));
WooCommerce wooCommerce = new WooCommerceAPI(config, ApiVersionType.V2);
Map<String, Object> params = new HashMap<>();
params.put("stock_quantity","26");
Map product = wooCommerce.update(EndpointBaseType.PRODUCTS.getValue(),41169,params);
System.out.println(String.valueOf(product.size())+ product.toString());
错误代码
{code=rest_cannot_access, message=Only authenticated users can access the
REST API., data={status=401}}
当我尝试检索产品数据时,它工作正常。