尝试在 Firebase Cloud Functions 中使用 Firebase Cloud Messaging 发送推送通知时未找到请求的实体 [英] Requested entity was not found when trying to send a push notification using Firebase Cloud Messaging in Firebase Cloud Functions
问题描述
我正在尝试使用以下代码通过 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.
这篇关于尝试在 Firebase Cloud Functions 中使用 Firebase Cloud Messaging 发送推送通知时未找到请求的实体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!