[英]How to add product image via the woocommerce REST API?
我正在使用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中獲取圖像,那么一切都很好。 但是,如果我使用另一個站點的鏈接,則會收到錯誤消息。
我有一個類似的問題,在WordPress內部cURL生成的錯誤導致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版本編譯,該版本使用優勝美地下的Apple安全傳輸,URL請求的目標不支持SSLv3(可能由於POODLE漏洞而被禁用)。
我的猜測是,通過cURL使用SSL時遇到錯誤。
您是否嘗試過使用http
鏈接而不是https
嘗試過?
如果您可以調試服務器端,請查看第1700行附近的class-wc-api-products.php
內部發生的情況。這就是產生錯誤的原因。 您可能遇到SSL錯誤。
如果是同一類型的SSL問題,則可能的解決方案是
http
代替https
),或者 在Woocommerce REST API庫中,您還可以設置選項以不驗證SSL。
$options = array(
'debug' => true,
'return_as_array' => false,
'validate_url' => false,
'timeout' => 60,
'ssl_verify' => false,
);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.