Curl API v3 不适用于产品创建 - 身份验证错误
Curl API v3 not working for Product Creating - Authentication Error
我正在尝试将产品上传到 Woo commerce Store,但在上传时它给了我以下错误代码,我不确定哪里出错了。
我注意到在一个案例中,如果帮助我,我是否应该包含任何 Lib 才能工作
仅供参考:这是 woocommerce 的 V3 API 代码
错误代码
{"errors":[{"code":"woocommerce_api_authentication_error","message":"oauth_consumer_key parameter is missing"}]}
我的代码
$aData = array(
'product' => array(
'title' => 'Premium Quality',
'type' => 'simple'
)
);
$sData = json_encode($aData);
$ch = curl_init('http://example.com/demo/ir/wc-api/v3/products');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_POSTFIELDS, $sData);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERPWD, 'ck_xxxxxxxxxxxxxxxxxx:cs_xxxxxxxxxxxxxxxxxxx');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($sData))
);
$result = curl_exec($ch);
print_r($result);
我正在使用 kloon-WooCommerce-REST-API-Client-Library。
升级到 v3 后我遇到了类似的问题。我通读了 class-wc-api-authentication.php 中的身份验证过程,发现不同之处在于我需要在使用它签署我的参数字符串之前将未编码的 & 附加到消费者机密.
$secret = $consumer_secret . '&';
我正在尝试将产品上传到 Woo commerce Store,但在上传时它给了我以下错误代码,我不确定哪里出错了。
我注意到在一个案例中,如果帮助我,我是否应该包含任何 Lib 才能工作
仅供参考:这是 woocommerce 的 V3 API 代码
错误代码
{"errors":[{"code":"woocommerce_api_authentication_error","message":"oauth_consumer_key parameter is missing"}]}
我的代码
$aData = array(
'product' => array(
'title' => 'Premium Quality',
'type' => 'simple'
)
);
$sData = json_encode($aData);
$ch = curl_init('http://example.com/demo/ir/wc-api/v3/products');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_POSTFIELDS, $sData);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERPWD, 'ck_xxxxxxxxxxxxxxxxxx:cs_xxxxxxxxxxxxxxxxxxx');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($sData))
);
$result = curl_exec($ch);
print_r($result);
我正在使用 kloon-WooCommerce-REST-API-Client-Library。 升级到 v3 后我遇到了类似的问题。我通读了 class-wc-api-authentication.php 中的身份验证过程,发现不同之处在于我需要在使用它签署我的参数字符串之前将未编码的 & 附加到消费者机密.
$secret = $consumer_secret . '&';