xpzouying/xiaohongshu-mcp · error

绑定商品失败

Error message

绑定商品失败

What it means

Raised in submitPublish when bindProducts fails to attach the requested product links to the note. It wraps the underlying DOM/commerce-panel error so the caller knows binding products, not another publish step, failed.

Source

Thrown at xiaohongshu/publish.go:402

			return errors.Wrap(err, "设置定时发布失败")
		}
		slog.Info("定时发布设置完成", "schedule_time", scheduleTime.Format("2006-01-02 15:04"))
	}

	if err := setVisibility(page, visibility); err != nil {
		return errors.Wrap(err, "设置可见范围失败")
	}

	// 处理原创声明:显式请求了原创但设置失败 → 报错中止,不静默发成非原创(避免"以为原创其实不是")
	if isOriginal {
		if err := setOriginal(page); err != nil {
			return errors.Wrap(err, "设置原创声明失败(已请求原创,中止发布)")
		}
		slog.Info("已声明原创")
	}

	if err := bindProducts(ctx, page, products); err != nil {
		return errors.Wrap(err, "绑定商品失败")
	}

	if err := clickPublishButton(page); err != nil {
		return err
	}

	// 校验发布真的成功:成功后创作平台会跳转离开发布页;未跳转则判定失败,
	// 消除"点了发布按钮就算成功"的假阳性。
	return waitPublishSuccess(page, 15*time.Second)
}

// waitPublishSuccess 轮询等待发布成功的信号:小红书发布成功后会跳转离开发布表单页
// (URL 不再含 /publish/publish)。超时仍未跳转 → 判定发布失败。
func waitPublishSuccess(page *rod.Page, timeout time.Duration) error {
	deadline := time.Now().Add(timeout)
	for {
		if info, err := page.Info(); err == nil && !strings.Contains(info.URL, "/publish/publish") {
			slog.Info("发布成功,已跳转离开发布页", "url", info.URL)

View on GitHub (pinned to 332d196854)

Solutions

  1. Confirm the account has commerce/product-binding access on Xiaohongshu
  2. Verify each product ID is valid and on-shelf
  3. Call Publish with an empty products list if binding is optional
  4. Inspect the wrapped cause and update the library if the product panel DOM changed

Example fix

// before
err := xhs.Publish(..., products=[]string{"999999"}) // invalid/off-shelf product
// after
err := xhs.Publish(..., products=validOnShelfProductIDs) // filtered/validated IDs
Defensive patterns

Strategy: validation

Validate before calling

for _, id := range products {
    if !isOnShelf(id) { return errors.Errorf("商品 %s 已下架或无效", id) }
}
if !accountHasCommerceAccess { products = nil }

Try / catch

if err := xhs.Publish(...); err != nil {
    if strings.Contains(err.Error(), "绑定商品失败") {
        // retry without products, or fix product list
    }
}

Prevention

When it happens

Trigger: Calling Publish with a non-empty products list while the product-binding panel cannot be opened, no products match, or the product selection UI fails to interact.

Common situations: Account lacks product-binding/commerce permission; product IDs no longer exist or are off-shelf; Xiaohongshu changed the product panel DOM.

Related errors


AI-assisted analysis of xpzouying/xiaohongshu-mcp@332d196854 (2026-09-05). Data as JSON: /api/errors/47e07e4d487fc7a0. Report an issue: GitHub.