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

FCM multicast报错messaging/registration-token-not-registered如何定位对应token

结论

sendMulticast 返回的 responses 数组和你传入的 tokenChunk 数组 严格按索引顺序一一对应,你提到的 success.responses[4] 出现报错就对应 tokenChunk[4] 的判断完全正确。
这个顺序对应关系是Firebase Admin SDK的固定设计约定,所有批量消息接口的返回结果都会保持和入参token数组的顺序一致,不需要额外做映射匹配。

修正后的代码实现

你只需要在遍历 responses 时取索引参数,就能匹配到对应的无效token做删除处理:

firebaseAdmin.messaging().sendMulticast({
    notification: {
        title: title,
        body: message,
    },
    data: data,
    tokens: tokenChunk,
})
.then((success) => {
    if (success.responses) {
        // 增加index参数取当前遍历下标
        success.responses.forEach((response, index) => {
            if (response.error) {
                if (response.error?.errorInfo?.code === 'messaging/registration-token-not-registered') {
                    // 直接取同下标的token即为无效token
                    const invalidToken = tokenChunk[index];
                    // 这里执行你的删除无效token逻辑
                }
            }
        });
    }
    return success;
})

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.09.25 13:24:03