首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何通过woocommerce REST API添加产品镜像?

如何通过woocommerce REST API添加产品镜像?
EN

Stack Overflow用户
提问于 2015-04-15 17:45:21
回答 2查看 10.7K关注 0票数 2

我正在使用Woocommerce REST API,需要添加一个产品到商店。

它以前是有效的。现在我有了这个错误:

代码语言:javascript
复制
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添加产品的文档

下面是我的代码:

代码语言:javascript
复制
$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获得图片,那么一切都很好。但是,如果我使用来自另一个站点的链接,那么我会得到一个错误。

EN

回答 2

Stack Overflow用户

发布于 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的回答中,

  1. 使用不安全的图像链接(http而不是https),或者
  2. 遵循Asaph的步骤使用OpenSSL而不是SecureSSL安装PHP
票数 2
EN

Stack Overflow用户

发布于 2017-11-09 08:46:11

在Woocommerce REST API库中,您还可以将选项设置为不验证SSL。

代码语言:javascript
复制
$options = array(
    'debug'           => true,
    'return_as_array' => false,
    'validate_url'    => false,
    'timeout'         => 60,
    'ssl_verify'      => false,
);
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29646900

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档