【发布时间】: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