|
|
@@ -99,7 +99,7 @@ def spapi_request(method, path, query, body=None, access_token=None):
|
|
|
# ==================== 主程序 ====================
|
|
|
if __name__ == "__main__":
|
|
|
print("=" * 60)
|
|
|
- print("A+ Content 完整流程 - marketplaceId 修正版")
|
|
|
+ print("A+ Content 完整流程 - 响应解析修正版")
|
|
|
print("=" * 60)
|
|
|
|
|
|
# Step 0
|
|
|
@@ -129,7 +129,7 @@ if __name__ == "__main__":
|
|
|
content_md5 = base64.b64encode(md5_hash).decode('utf-8')
|
|
|
print(f" 图片大小: {len(image_binary)} bytes")
|
|
|
|
|
|
- # Step 2: Uploads API 用 marketplaceIds(复数)✅
|
|
|
+ # Step 2
|
|
|
print("\n📝 Step 2: 创建上传目标...")
|
|
|
resource = "aplus/2020-11-01/contentDocuments"
|
|
|
path = f"/uploads/2020-11-01/uploadDestinations/{quote(resource, safe='/')}"
|
|
|
@@ -164,7 +164,7 @@ if __name__ == "__main__":
|
|
|
# 构建 contentDocument
|
|
|
content_doc = {
|
|
|
"name": "Product Image",
|
|
|
- "contentType": "EMC",
|
|
|
+ "contentType": "EBC",
|
|
|
"locale": "en-US",
|
|
|
"contentModuleList": [
|
|
|
{
|
|
|
@@ -207,19 +207,15 @@ if __name__ == "__main__":
|
|
|
]
|
|
|
}
|
|
|
|
|
|
- # Step 4: 验证 - A+ API 用 marketplaceId(单数)❌ 之前错了
|
|
|
+ # Step 4: 验证
|
|
|
print("\n📝 Step 4: 验证内容文档...")
|
|
|
validate_body = {"contentDocument": content_doc}
|
|
|
-
|
|
|
- # 关键修正:A+ Content API 用 marketplaceId(单数)
|
|
|
resp = spapi_request("POST", "/aplus/2020-11-01/contentAsinValidations", f"marketplaceId={MARKETPLACE_ID}", body=validate_body, access_token=token)
|
|
|
print(f" 验证状态码: {resp.status_code}")
|
|
|
print(f" 验证响应: {resp.text[:800]}")
|
|
|
|
|
|
- # Step 5: 创建文档 - A+ API 用 marketplaceId(单数)❌ 之前错了
|
|
|
+ # Step 5: 创建文档
|
|
|
print("\n📝 Step 5: 创建 Content Document...")
|
|
|
-
|
|
|
- # 关键修正:A+ Content API 用 marketplaceId(单数)
|
|
|
resp = spapi_request("POST", "/aplus/2020-11-01/contentDocuments", f"marketplaceId={MARKETPLACE_ID}", body={"contentDocument": content_doc}, access_token=token)
|
|
|
print(f" 状态码: {resp.status_code}")
|
|
|
print(f" 响应: {resp.text}")
|
|
|
@@ -228,21 +224,19 @@ if __name__ == "__main__":
|
|
|
print("\n ❌ 创建失败")
|
|
|
exit(1)
|
|
|
|
|
|
+ # 关键修正:实际响应是 {"contentReferenceKey":"..."},不是 {"contentReference":{"key":"..."}}
|
|
|
doc_data = resp.json()
|
|
|
- content_ref = doc_data.get("contentReference", {})
|
|
|
- content_key = content_ref.get("key")
|
|
|
+ content_key = doc_data.get("contentReferenceKey") # ← 修正点
|
|
|
|
|
|
if not content_key:
|
|
|
- print(" ❌ 响应中缺少 contentReference.key")
|
|
|
+ print(" ❌ 响应中缺少 contentReferenceKey")
|
|
|
exit(1)
|
|
|
|
|
|
print(f" ✅ 创建成功,Content Key: {content_key}")
|
|
|
|
|
|
- # Step 6: 绑定 ASIN - A+ API 用 marketplaceId(单数)❌ 之前错了
|
|
|
+ # Step 6: 绑定 ASIN
|
|
|
print("\n🔗 Step 6: 绑定 ASIN...")
|
|
|
body = {"asinSet": [ASIN]}
|
|
|
-
|
|
|
- # 关键修正:A+ Content API 用 marketplaceId(单数)
|
|
|
resp = spapi_request("POST", f"/aplus/2020-11-01/contentDocuments/{content_key}/asins", f"marketplaceId={MARKETPLACE_ID}", body=body, access_token=token)
|
|
|
print(f" 状态码: {resp.status_code}")
|
|
|
print(f" 响应: {resp.text[:500]}")
|
|
|
@@ -252,10 +246,8 @@ if __name__ == "__main__":
|
|
|
exit(1)
|
|
|
print(" ✅ ASIN 绑定成功")
|
|
|
|
|
|
- # Step 7: 提交审核 - A+ API 用 marketplaceId(单数)❌ 之前错了
|
|
|
+ # Step 7: 提交审核
|
|
|
print("\n📋 Step 7: 提交审核...")
|
|
|
-
|
|
|
- # 关键修正:A+ Content API 用 marketplaceId(单数)
|
|
|
resp = spapi_request("POST", f"/aplus/2020-11-01/contentDocuments/{content_key}/approvalSubmissions", f"marketplaceId={MARKETPLACE_ID}", access_token=token)
|
|
|
print(f" 状态码: {resp.status_code}")
|
|
|
print(f" 响应: {resp.text[:500]}")
|