【发布时间】:2021-02-23 07:58:20
【问题描述】:
当我们使用 Firebase Admin SDK 向 iOS 设备发送 FCM 数据消息时,我们会遇到以下异常。
com.google.firebase.messaging.FirebaseMessagingException: Request contains an invalid argument.
我们正在使用com.google.firebase:firebase-admin:6.7.0,消息是这样构建的。
Message.builder()
.setApnsConfig(ApnsConfig.builder()
.putHeader("apns-priority", "10")
.setAps(Aps.builder()
.setContentAvailable(true)
.build())
.build())
.putAllData(data)
.setToken(token)
.build();
我认为令牌本身没有问题,因为向该令牌发送推送通知是可行的。
消息大小也不应该成为问题,因为它基本上只是其中的一个 id。
我不确定它是否会在所有 iOS 设备上发生。 我在构建数据消息时遗漏了什么吗?
更新
我检查了异常中包含的详细信息,似乎令牌有问题。
{
"error": {
"code": 400,
"message": "Request contains an invalid argument.",
"status": "INVALID_ARGUMENT",
"details": [
{
"@type": "type.googleapis.com/google.firebase.fcm.v1.FcmError",
"errorCode": "INVALID_ARGUMENT"
},
{
"@type": "type.googleapis.com/google.rpc.BadRequest",
"fieldViolations": [
{
"field": "message.token",
"description": "Invalid registration token"
}
]
}
]
}
}
但是当我使用邮递员向同一个令牌发送数据消息时,没有错误,响应看起来像这样。
{
"multicast_id": 7455611938954436367,
"success": 1,
"failure": 0,
"canonical_ids": 0,
"results": [
{
"message_id": "0:1614145427166557%c5757de0f9fd7ecd"
}
]
}
【问题讨论】:
-
检查异常中包含的其他详细信息(尤其是来自 FCM 的 HTTP 响应负载)。这应该提供一些关于正在发生的事情的提示。
-
我用更多信息更新了我的问题。 firebase 有没有办法查看日志或其他东西以更好地了解这些消息发生了什么?
标签: ios firebase firebase-cloud-messaging firebase-admin