【问题标题】:Need help and info Tips about Woocommerce create order API需要帮助和信息有关 Woocommerce 创建订单 API 的提示
【发布时间】:2017-03-13 05:58:45
【问题描述】:

我想进行 API 调用。我正在为 WordPress 使用 Woocommerce 插件。我正在尝试使用 kloon/WooCommerce-REST-API-Client-Library

设置 API

所以我使用基本的 api 命令来创建订单

我的代码:

<?php

require_once( '../lib/woocommerce-api.php' );

$consumer_key = 'ck_0cfc7bc73277efd3eb665b52234ae8939b39cb0a'; // Add your own Consumer Key here
$consumer_secret = 'cs_ef229872c4620c46d1b71b52537b3279e0e9dcdb'; // Add your own Consumer Secret here
$store_url = 'http://example.net'; // Add the home URL to the store you want to connect to here

$options = array(
    'debug'           => true,
    'return_as_array' => false,
    'validate_url'    => false,
    'timeout'         => 30,
    'ssl_verify'      => false,
);

try {

    $client = new WC_API_Client( $store_url, $consumer_key, $consumer_secret, $options );

    print_r( $client->orders->create( $data ) );

} catch ( WC_API_Client_Exception $e ) {

    echo $e->getMessage() . PHP_EOL;
    echo $e->getCode() . PHP_EOL;

    if ( $e instanceof WC_API_Client_HTTP_Exception ) {

        print_r( $e->get_request() );
        print_r( $e->get_response() );
    }
}

我的错误:

错误:缺少参数数据 [woocommerce_api_missing_callback_param] 400 标准类对象([标题] => 数组([0] => 接受: 应用程序/json 1 => 内容类型:应用程序/json [2] => 用户代理:WooCommerce API Client-PHP/2.0.1 ) [方法] => POST [url] => http://example.net/test/wc-api/v2/orders?oauth_consumer_key=ck_0cfc7bc73277efd3eb665b52234ae8939b39cb0a&oauth_timestamp=1477892703&oauth_nonce=08e418dcf02c304ccfab4d09ed3233074acc4f11&oauth_signature_method=HMAC-SHA256&oauth_signature=HqW4ra%2F3EPhnByREOQjG9VybB2FjSpDJhC0PVVSnUZ8%3D [参数] => 数组([oauth_consumer_key] => ck_0cfc7bc73277efd3eb665b52234ae8939b39cb0a [oauth_timestamp] => 1477892703 [oauth_nonce] => 08e418dcf02c304ccfab4d09ed3233074acc4f11 [oauth_signature_method] => HMAC-SHA256 [oauth_signature] => HqW4ra/3EPhnByREOQjG9VybB2FjSpDJhC0PVVSnUZ8= ) [数据] => [正文] => null [持续时间] => 1.14179 ) 标准类对象 ( [body] => {“错误”:[{“代码”:“woocommerce_api_missing_callback_param”,“消息”:“丢失 参数数据"}]} [code] => 400 [headers] => Array ([Date] => Mon, 2016 年 10 月 31 日 05:45:04 GMT [服务器] => Apache/2.2.27 (Unix) mod_ssl/2.2.27 OpenSSL/1.0.1e-fips [X-Powered-By] => PHP/5.6.26 [Vary] => Accept-Encoding [Connection] => close [Transfer-Encoding] => chunked [Content-Type] => application/json;字符集=UTF-8 ) )

有人可以帮助我吗?我该怎么办 ?

【问题讨论】:

    标签: php wordpress api woocommerce


    【解决方案1】:

    我们可以通过将PUT 请求替换为POST 请求来解决更新订单时出现的奇怪woocommerce_api_missing_callback_param 错误。 在我们的例子中,服务器上的某些东西似乎阻止了 PUT 参数。

    【讨论】:

      【解决方案2】:

      在代码中,您尚未定义 $ 数据数组及其应捕获的数据类型。根据您使用的api库尝试:

      print_r( $client
                ->products
                ->create( array( 
                  'title' => 'Test Product', 
                  'type' => 'simple', 
                  'regular_price' => '9.99', 
                  'description' => 'test' ) ) 
      );
      

      【讨论】:

        猜你喜欢
        • 2014-08-04
        • 1970-01-01
        • 2020-09-06
        • 1970-01-01
        • 2012-12-01
        • 2013-09-19
        • 1970-01-01
        • 2011-08-20
        • 1970-01-01
        相关资源
        最近更新 更多