【问题标题】:Firebase Cloud Messaging - "success" and "failure" in response JSONFirebase 云消息传递 - 响应 JSON 中的“成功”和“失败”
【发布时间】:2016-08-18 10:30:19
【问题描述】:

我使用 Firebase 云消息传递向我的 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 总是真的吗?

【问题讨论】:

    标签: android json firebase firebase-cloud-messaging firebase-notifications


    【解决方案1】:

    here 所述:

    success - 必需,已处理的消息数 没有错误。

    failure - 必需,消息数量 无法处理。

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

    【讨论】:

    【解决方案2】:
    total number of requests to FCM server = success + failure
    

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

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

    【讨论】:

      【解决方案3】:

      如上所述,我得到了回应:

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

      就我而言,1 个 fcmtoken 已过期,因此 1 个失败。

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

      【讨论】:

        【解决方案4】:

        添加通知参数以及 dataregistration_ids

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

        【讨论】:

          猜你喜欢
          • 2019-12-15
          • 2016-09-19
          • 1970-01-01
          • 2021-01-29
          • 1970-01-01
          • 2018-01-09
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多