php - Woocommerce api:使用图像创建产品 - 错误请求
问题描述
我正在尝试通过创建带有图像的产品,Woocommerce Rest API
但我得到bad request
:
这是我准备的方法images array
:
//IMAGES
$images = [];
//Get the featured image
$featured_image_url = wp_get_attachment_image_src( get_post_thumbnail_id($post_id));
//and push it in the images array with position = 0 (featured)
array_push($images, ['src' => $featured_image_url[0], 'position' => 0]);
//Get All the images
$attachmentIds = $product->get_gallery_attachment_ids();
$pos = 1;
foreach( $attachmentIds as $attachmentId )
{
array_push($images, ['src' => wp_get_attachment_image_src( $attachmentId ), 'position' => $pos]);
$pos++;
}
这是在产品发布后调用的代码,当我在其图库中发布具有特色图像和另外 2 个图像的产品时,我将其作为$images
数组:
Array
(
[0] => Array
(
[src] => http://src_image-150x150.jpg
[position] => 0
)
)
我只得到特色图片,并且bad request
在我发送此帖子请求以创建产品时收到。如果我注释掉images
请求的属性,则产品创建成功。
解决方案
推荐阅读
- azure-cosmosdb - Azure Cosmos db 的最小 TTL 值应该是多少,以便更改源
- laravel - 从不同目录检索图像
- python - 自动重新加载失败。ModuleNotFoundError : 未找到该模块的规范
- mysql - MySQL 从任何地方创建使用权限失败
- javascript - 如何在 1 分钟后停止音频播放事件?
- java - 带有静态框架的活动
- visual-studio - 包含一个 .propdesc 文件作为资源并从 DllRegisterServer 注册它
- javascript - 我如何让我的 javascript 函数等待 WebSql 事务完成后再继续
- python - vscode 似乎没有激活我的虚拟 python 环境
- angular - 来自父组件的子组件中的角度调用函数