Firebase 云消息传递 - "success" 和 "failure" 响应 JSON

Firebase Cloud Messaging - "success" and "failure" in response JSON

我使用 Firebase Cloud Messaging 向我的 Android 客户端应用程序发送通知,每个通知都应根据其注册令牌发送到单个设备。

每次我通过 https://fcm.googleapis.com/fcm/send 发送通知时,我都会收到这样的 JSON 响应:

{
  "multicast_id": 108,
  "success": 1,
  "failure": 0,
  "canonical_ids": 0,
  "results": [
    { "message_id": "1:08" }
  ]
}

我发现 successfailure 多余 - 它们不是同一个意思吗?我应该检查它们以确保一切正常吗? success != failure 总是正确的吗?

如所述here

success - Required, number of messages that were processed without an error.

failure - Required, number of messages that could not be processed.

你得到: "success": 1,表示成功处理了1条消息 "failure":0,表示没有错误

total number of requests to FCM server = success + failure

成功和失败的总和构成了请求的总数。在您的情况下,当您只发送给一个用户时,没关系。但是当你发送给多个用户时,你可以得到成功和失败,并将它们加起来就知道有多少请求被发送到 FCM 服务器。

参考:https://firebase.google.com/docs/cloud-messaging/http-server-ref#interpret-downstream

添加通知参数以及 dataregistration_ids.

{"notification":{"title":"","body":""},"data":{},"registration_ids":["acaxdYt5464262hghdsd*****"]
}

如上回复所述,我得到:

{{
success: true,
messageId: someid,
},
{
success: false,
error: [yourerror],
},
successCount: 1,
failureCount:1,
}

在我的例子中,1 个 fcmtoken 已过期,因此 1 个失败。

successCount 表示发送了多少通知,failureCount 表示导致错误的标记。