Laravel调用WIX博客REST API创建文章:列表页图片不显示求助
问题:WIX博客列表页图片无法显示(单篇文章页面正常)
使用Laravel发送POST请求调用WIX博客REST API创建文章,所有功能正常,但博客列表页的图片无法显示,单篇文章页面的图片显示正常。请求体中的草稿文章对象代码如下:
$post_field = [ "draftPost" => [ "title" => $topic->topic, "memberId" => $memberId, "heroImage" => [ "id" => "b5067f_24e7cb534efa4ca2843a24a29f7a8d8a~mv2.jpeg", "url" => "https://static.wixstatic.com/media/b5067f_24e7cb534efa4ca2843a24a29f7a8d8a~mv2.jpeg", "altText" => $topic->topic, ], "richContent" => [ "nodes" => [ [ "type" => "IMAGE", "id" => "", "imageData" => [ "containerData" => [ "width" => [ "custom" => "700px", ], "alignment" => "CENTER", "spoiler" => [ "enabled" => false, ], "height" => [ "custom" => "800px", ], "textWrap" => true, ], "image" => [ "src" => [ "private" => false, "url" => "https://static.wixstatic.com/media/b5067f_24e7cb534efa4ca2843a24a29f7a8d8a~mv2.jpeg", "id" => "b5067f_24e7cb534efa4ca2843a24a29f7a8d8a~mv2.jpeg", ], ] ] ], [ "type" => "HTML", "id" => "", "htmlData" => [ "containerData" => [ "width" => [ "custom" => "750px", "spoiler" => [ "enabled" => true ], ], "height" => [ "custom" => "12000px" ], "alignment" => "CENTER" ], "source" => "HTML", "html" => "{$topic->fullBlog->content}" ] ] ] ], "media" => [ "displayed" => true, "wixMedia" => [ "image" => [ "id" => "b5067f_24e7cb534efa4ca2843a24a29f7a8d8a~mv2.jpeg", "altText" => $topic->topic, ] ] ] ], "publish" => true, "fieldsets" => ["URL"] ];
其中$topic->fullBlog->content包含h2、p、a等HTML标签,均能正常显示。
解决方案
问题原因
WIX博客列表页会优先读取heroImage或media字段中的适配尺寸图片(缩略图),而当前请求体中仅提供了原图的ID和URL,未包含列表页所需的尺寸参数或适配格式,导致列表页无法加载正确的图片资源。
修改方案
- 为
heroImage添加适配列表页的尺寸参数:使用WIX媒体的图片处理URL(带v1/fill/参数),指定适合列表展示的宽高,同时补充width和height属性。 - 完善
media.wixMedia.image字段:添加带尺寸参数的图片URL,确保列表页能读取到有效缩略图地址。
修改后的关键代码片段:
$post_field = [ "draftPost" => [ // ... 其他字段保持不变 "heroImage" => [ "id" => "b5067f_24e7cb534efa4ca2843a24a29f7a8d8a~mv2.jpeg", // 带列表页适配尺寸的WIX媒体URL "url" => "https://static.wixstatic.com/media/b5067f_24e7cb534efa4ca2843a24a29f7a8d8a~mv2.jpeg/v1/fill/w_600,h_400,al_c,q_80,enc_auto/", "altText" => $topic->topic, "width" => 600, "height" => 400 ], // ... 其他字段保持不变 "media" => [ "displayed" => true, "wixMedia" => [ "image" => [ "id" => "b5067f_24e7cb534efa4ca2843a24a29f7a8d8a~mv2.jpeg", "altText" => $topic->topic, // 添加列表页缩略图URL "url" => "https://static.wixstatic.com/media/b5067f_24e7cb534efa4ca2843a24a29f7a8d8a~mv2.jpeg/v1/fill/w_300,h_200,al_c,q_80,enc_auto/" ] ] ] ], // ... 其他字段保持不变 ];
补充说明
- 图片必须已上传至WIX媒体库,否则ID无效,无法生成适配尺寸的缩略图。
- 可根据列表页的布局需求调整
w_600,h_400等尺寸参数,al_c表示居中裁剪,q_80为图片质量。
内容的提问来源于stack exchange,提问作者Sarwar Zahan
相关产品推荐
相关产品推荐

