在Firebase Cloud Functions中尝试使用Firebase Cloud Messaging发送推送通知时,找不到请求的实体

在Firebase Cloud Functions中尝试使用Firebase Cloud Messaging发送推送通知时,找不到请求的实体

问题描述:

我正在尝试通过FCM从Firebase Cloud函数通过以下代码发送多播通知:

I'm trying to send a multicast notification via FCM from a Firebase Cloud function with the following code:

const message = {
    tokens: recipients,
    notification: {
        title: title,
        body: body
    },
    data: {
        projectPartnerId: projectPartnerId
    }
};
return admin.messaging().sendMulticast(message);

并且没有发送任何推送通知.每个响应都包含一条错误,并带有相同的消息:未找到请求的实体".

And none of the push notifications is getting sent. Each response contains an error with the same message: "Requested entity was not found".

我在Google Cloud控制台中启用了该API(Firebase文档中的任何地方都未提及,但显然这是必需的).我不知道还能做什么.我可以找到的所有其他问题都与HTTP API或旧版API有关.我正在使用最新版本的Firebase Admin SDK.

I enabled the API in the Google Cloud console (which was not mentioned anywhere in the Firebase documentation but apparently that was necessary). I don't know what else I can do. And all the other questions I could find related to the HTTP API or the legacy API. I'm using the latest version of the Firebase Admin SDK.

弄清楚了.因此很明显,当我尝试发送的FCM令牌不再注册时,就会发生此错误,如"messaging/registration-token-not-registered"错误代码所证明的.在那种情况下,我只需要从用户的令牌中删除该令牌并完成它即可.

Figured it out. So apparently, this error happens when the FCM token I'm trying to send to is not registered anymore, as evidenced by the "messaging/registration-token-not-registered" error code. In that case I just need to remove this token from the user's token and be done with it.