1

编辑:如果有人正在阅读这篇文章,我在记录 v2 api 之前发表了这篇文章,但是文档现在可用,所以如果您遇到问题,请参阅:http ://woothemes.github.io/woocommerce-rest- api-docs/#introduction


我正在尝试更新此处找到的 PHP REST API 客户端库:https ://github.com/kloon/WooCommerce-REST-API-Client-Library 。

我将 API_ENDPOINT 更改为 wc-api/v2/ 并添加了此功能:

public function create_order( $data ) {
    return $this->_make_api_call( 'orders/', $data, 'POST' );
}

我得到:

Warning:  rawurldecode() expects parameter 1 to be string, array given in /home/class-wc-api-client-    v2.php on line 441
Warning:  rawurldecode() expects parameter 1 to be string, array given in /home/class-wc-api-client-v2.php on line 441
  object(stdClass)#1801 (1) {
 ["errors"]=>
 array(1) {
   [0]=>
   object(stdClass)#1798 (2) {
     ["code"]=>
     string(3) "401"
     ["message"]=>
     string(19) "cURL HTTP error 401"
   }
 }
}

我正在使用以下代码调用 create_order

$data = array(
    "status" => "processing",
    "payment_details" => array("method_id" => "paypal", "method_title" => "PayPal", "paid" => 1),
    "line_items" => array("id" => 123, "subtotal" => 45.00, "total" => 45.00, "total_tax" => 0.00, "price" => 45.00, "quantity" => 1, "name" => "itemName", "product_id" => 123)
);
var_dump($wc_api->create_order($data));

有什么帮助吗?

谢谢!

4

2 回答 2

1

Though I didn't work with WooCommerce API or the API client you mentioned, the first thing I noticed was cURL HTTP error 401, probably authentication error. Please double check consumer key & secret.

Second thing was warning produced in rawurldecode() function (method). You're passing array but the function is expecting string. So check that part carefully as well.

于 2014-11-13T08:17:02.383 回答
1

目前,API 和您正在使用的库中都存在 rawurlencode 问题

身份验证错误是因为您的端点是“订单/”,它应该是“订单”(没有斜线)

于 2015-02-03T16:42:51.330 回答