You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

通过Wix API创建含图片的博客草稿:图片不显示问题求助

Wix API博客文章图片添加失败问题

我拥有一个公开的Wix博客,此前一直通过Wix后台添加文章,现在希望使用Wix API完成文章发布操作。目前文章标题和文本内容均可正常添加,但始终无法通过API为文章添加图片。我已严格按照官方文档操作,尝试了多种实现方式,但每次创建的草稿中仅能看到自定义的标题和内容,图片始终不显示:

# Set up the API endpoint and headers
url = "https://www.wixapis.com/blog/v3/draft-posts"

headers = {
    "Authorization": "example_token_generated_from_wix_documentation_https://dev.wix.com/api/rest/authorization/oauth-2/request-an-access-token",
    "Content-Type": "application/json"
}

# Set up the rich content of the blog post
rich_content = {
    "nodes": [
        {
            "type": "PARAGRAPH",
            "id": "",
            "nodes": [
                {
                    "type": "IMAGE",
                    "id": "",
                    "nodes": [],
                    "imageData": {
                        "type": "SITE",
                        "siteData": {
                            "url": f"https://static.wixstatic.com/media/image_id~mv2.jpg"
                        }
                    }
                }
            ],
            "paragraphData": {
                "textStyle": {"textAlignment": "CENTER"},
                "indentation": 0
            }
        },
        {
            "type": "PARAGRAPH",
            "id": "",
            "nodes": [
                {
                    "type": "TEXT",
                    "id": "",
                    "nodes": [],
                    "textData": {
                        "text": "My blog post content goes here.",
                        "decorations": []
                    }
                }
            ],
            "paragraphData": {
                "textStyle": {"textAlignment": "AUTO"},
                "indentation": 0
            }
        }
    ]
}

# Set up the draft post data
data = {
    "draftPost": {
        "title": "My Blog Post Title",
        "richContent": rich_content,
        "heroImage": {
            "type": "SITE",
            "siteData": {
                "url": "https://static.wixstatic.com/media/123~mv2.jpg"
            }
        }
    }
}


# Make the API call
response = requests.post(url, headers=headers, data=json.dumps(data))

更新1
我曾怀疑是权限不足导致仅文本可见,但即使直接加载本地图片并转为Base64编码,草稿创建成功且返回状态码200,图片仍无法显示:

# Read the image data from disk and encode it in base64
with open('image.png', 'rb') as f:
    image_data = base64.b64encode(f.read()).decode()

# Set up the rich content of the blog post
rich_content = {
    "nodes": [
        {
            "type": "PARAGRAPH",
            "id": "",
            "nodes": [
                {
                    "type": "TEXT",
                    "id": "",
                    "nodes": [],
                    "textData": {
                        "text": "My example blog post content 1.",
                        "decorations": []
                    }
                }
            ]
        },
        {
            "type": "IMAGE",
            "id": "",
            "nodes": [
                {
                    "imageData": {
                        "image": {
                            "src": {
                                "base64": image_data,
                                "altText": "Example image"
                            }
                        }
                    }
                }
            ]
        },
        {
            "type": "PARAGRAPH",
            "id": "",
            "nodes": [
                {
                    "type": "TEXT",
                    "id": "",
                    "nodes": [],
                    "textData": {
                        "text": "My example blog post content 2.",
                        "decorations": []
                    }
                }
            ]
        },
        {
            "type": "IMAGE",
            "id": "",
            "nodes": [
                {
                    "imageData": {
                        "image": {
                            "src": {
                                "url": "https://static.wixstatic.com/media/image_id~mv2.jpg",
                                "altText": "Example image",
                                "private": True
                            }
                        }
                    }
                }
            ]
        },
    ]
}

# Set up the draft post data
data = {
    "draftPost": {
        "title": "My Blog Post Title",
        "richContent": rich_content
    }
}

# Make the API call
response = requests.post(url, headers=headers, data=json.dumps(data))
print(response.status_code)
# Check the response status code
if response.status_code == 200:
    print("Blog post created successfully!")
    print(response.text)
else:
    print("Failed to create blog post: " + str(response.text))

更新2
我发现按以下方式定义节点后,草稿中似乎存在图片对象但完全不可见(如图所示)。我已尝试使用Wix媒体管理器及外部站点的图片链接,且链接均可正常访问,但结果始终一致,求可行的解决思路:

{
    "type": "IMAGE",
    "id": "",
    "nodes": [
        {
            "type": "IMAGE",
            "id": "",
            "nodes": [],
            "imageData": {
                "image": {
                    "src": {
                        "url": "https://static.wixstatic.com/media/2d7149_6b51eeb779cd460099e98e7ce2f14e1c~mv2.jpg"
                    },
                    "height": 1920,
                    "width": 1080
                }
            }
        }
    ]
}

Wix草稿文章中的空白图片

内容的提问来源于stack exchange,提问作者John Smith

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.23 07:55:00