我正在使用Woocommerce REST API,需要添加一个产品到商店。
它以前是有效的。现在我有了这个错误:
stdClass Object ( [errors] => Array (
[0] => stdClass Object ( [code] =>
woocommerce_api_invalid_remote_product_image
[message] => Error getting remote image
https://www.google.lt/images/srpr/logo11w.png ) ) )以下是通过WooCommerce REST API http://woothemes.github.io/woocommerce-rest-api-docs/#create-a-product添加产品的文档
下面是我的代码:
$dataArray = array(
'title' => 'xxxxxxxxxx',
'description' => 'description1',
'price' => '69',
'sku' => 'sku2',
'tags' => 'tag1, tag2, tag3',
'color' => array('red', 'blue'),
'size' => array('S', 'M'),
'image' => 'https://www.google.lt/images/srpr/logo11w.png'
);
public function addProduct($data)
{
$wc_api = $this->_getClient();
$newProductData = array(
'product' => array(
'title' => $data['title'],
'type' => 'variable',
'regular_price' => $data['price'],
'description' => $data['description'],
'sku' => $data['sku'],
'tags' => [ $data['tags'] ],
'images' => [ array('src' => $data['image'], 'position' => '0') ],
'virtual' => true
)
);
return $wc_api->create_product($newProductData);
}我正在使用这个客户端调用REST API
https://github.com/kloon/WooCommerce-REST-API-Client-Library
编辑:如果我从woocommerce托管的wordpress获得图片,那么一切都很好。但是,如果我使用来自另一个站点的链接,那么我会得到一个错误。
发布于 2015-05-22 01:19:54
我遇到了类似的问题,cURL在WordPress中生成的导致woocommerce_api_invalid_remote_product_image的错误是{"errors":{"http_request_failed":["SSLRead() return error -9806"]},"error_data":[]},这意味着,根据https://stackoverflow.com/a/26538127/266531中的Asaph,
php是用约塞米蒂下使用苹果安全传输的cURL版本编译的,并且请求的目标不支持SSLv3 (可能是由于贵宾犬漏洞而被禁用)。
我的猜测是,您在cURL上使用SSL时遇到了错误。
你用http链接试过了吗?还是谢谢https吧
如果可以调试服务器端,请看一下1700行的class-wc-api-products.php内部发生了什么。这就是产生错误的原因。您可能遇到SSL错误。
如果它是同一类型的SSL问题,那么您可能的解决方案是
在https://stackoverflow.com/a/26538127/266531的回答中,
http而不是https),或者发布于 2017-11-09 08:46:11
在Woocommerce REST API库中,您还可以将选项设置为不验证SSL。
$options = array(
'debug' => true,
'return_as_array' => false,
'validate_url' => false,
'timeout' => 60,
'ssl_verify' => false,
);https://stackoverflow.com/questions/29646900
复制相似问题