【发布时间】:2015-06-21 05:13:18
【问题描述】:
我正在使用 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 获得图像,那么一切都很好。但是,如果我使用来自其他网站的链接,则会出现错误。
【问题讨论】:
-
外部图像将使用
wp_remote_get()获取。你有安装 cURL 吗?还是有什么东西阻止了外部请求? -
“卷曲已启用”。很酷,但配置正确吗?你测试过外部请求吗?
-
如果您可以调试服务器端,请查看第 1700 行附近的
class-wc-api-products.php内部发生了什么。这就是产生错误的原因。您可能遇到 SSL 错误。您是否尝试过使用http链接而不是感谢https?看到这个stackoverflow.com/questions/26461966/… -
我很确定
image['position']也应该是一个整数,尽管这似乎不会引发错误。
标签: php api curl woocommerce