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

问题描述 投票:0回答:6

我正在尝试使用以下代码通过 FCM 从 Firebase Cloud 功能发送多播通知:

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

并且没有发送任何推送通知。每个响应都包含一个带有相同消息的错误:“找不到请求的实体”。

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

firebase firebase-cloud-messaging firebase-admin
6个回答
60
投票

想通了。显然,当我尝试发送到的 FCM 令牌不再注册时,就会发生此错误,如

"messaging/registration-token-not-registered"
错误代码所示。在这种情况下,我只需要从用户的令牌中删除此令牌即可完成。


4
投票

正如@user1123432所述,我只是做了如下操作:

try {

// Logic to send a push notification goes here

 catch (e: Exception) {
    logger.error("Firebase Notification Failed: ${e.message}")
     if (e is FirebaseMessagingException) {
        logger.info("Firebase Notification token for the user: ${user.userName}, errorCodeName: ${e.errorCode.name}, messagingErrorCodeName: ${e.messagingErrorCode.name}")
        if (e.errorCode.name == "INVALID_ARGUMENT" || e.errorCode.name == "NOT_FOUND" || e.messagingErrorCode.name == "UNREGISTERED") {
            myNotificationTokenRepo.clearTokenByUserId(user.uuid)
            logger.info("Deleted Firebase Notification token for the user: ${user.userName}")
        }
    }
}

1
投票

我最近在为 iOS 应用程序设置推送通知时遇到了这个问题。我通过 this answerGitHub 线程 上发布的修复找到了成功的修复。问题是在

Info.plist
FirebaseAppDelegateProxyEnabled
中设置为 bool 而不是字符串,所以:

    <key>FirebaseAppDelegateProxyEnabled</key>
    </false>

成为

    <key>FirebaseAppDelegateProxyEnabled</key>
    <string>0</string>

GitHub 评论还描述了通过中型帖子实现风味,并将

Firebase/Messaging
添加到
Podfile
,这与使用 Flutter 构建 iOS 应用程序有关。我的项目是用 Flutter 构建的,但我们不需要实现任何风格或更新 Podfile,因为它是由 Flutter 本身管理的。


0
投票

在遇到同样的问题后,这对我来说成功了。

Info.plist
文件中我更改了此内容

<key>FirebaseAppDelegateProxyEnabled</key>
<false/>

进入这个

<key>FirebaseAppDelegateProxyEnabled</key>
<string>NO</string>

0
投票

我遇到了同样的问题,当我重新连接到数据库时问题得到解决,确保所有令牌都处于活动状态并正在使用中,并删除未使用的一次或更新它们


0
投票

我在使用 2 个具有相同配置的 Android 模拟器时遇到此问题,在使用 2 个具有不同配置的模拟器后问题消失了

© www.soinside.com 2019 - 2024. All rights reserved.