【问题标题】:Using API v2 of WooCommerce使用 WooCommerce 的 API v2
【发布时间】:2014-11-13 06:11:10
【问题描述】:

编辑: 万一有人在读这篇文章,我在记录 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));

有什么帮助吗?

谢谢!

【问题讨论】:

    标签: php wordpress woocommerce woothemes


    【解决方案1】:

    虽然我没有使用 WooCommerce API 或您提到的 API 客户端,但我注意到的第一件事是 cURL HTTP 错误 401,可能是身份验证错误。请仔细检查消费者密钥和秘密。

    第二件事是 rawurldecode() 函数(方法)中产生的警告。您正在传递数组,但该函数需要字符串。所以也要仔细检查那部分。

    【讨论】:

    • 谢谢,我想我会等他们更新他们的 php 客户端库!
    【解决方案2】:

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

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

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-04
    • 2015-09-30
    • 1970-01-01
    • 2015-10-26
    • 2023-04-03
    相关资源
    最近更新 更多