【发布时间】:2018-07-03 08:11:14
【问题描述】:
我正在尝试向主题发送 FCM 消息。但从服务器收到“提供的主题值无效”错误。
Json 有效负载
{
"message":{
"topic":"/topics/news",
"data":{
"title":"Hellow World",
"message":"This is the Topic Message",
"type1":"100",
"type2":"abc"
}
}
}
回应
{
"error":{
"code":400,
"message":"Request contains an invalid argument.",
"status":"INVALID_ARGUMENT",
"details":[
{
"@type":"type.googleapis.com/google.rpc.BadRequest",
"fieldViolations":[
{
"field":"message.topic",
"description":"Invalid topic value provided."
}
]
},
{
"@type":"type.googleapis.com/google.firebase.fcm.v1.FcmError",
"errorCode":"INVALID_ARGUMENT"
}
]
}
}
我尝试将主题值设为“新闻”(没有“/topics/”),但它会引发相同的错误。我可以毫无问题地从 firebase 控制台向主题发送消息。
任何帮助表示赞赏。 TIA
Edit1 - 下面的通知负载工作正常,但数据负载不起作用。根据文档,也允许数据有效负载https://firebase.google.com/docs/cloud-messaging/android/topic-messaging 请求
{
"message":{
"topic" : "foo-bar",
"notification" : {
"body" : "This is a Firebase Cloud Messaging Topic Message!",
"title" : "FCM Message",
}
}
}
编辑2: 这行得通。我的代码中有一个小错误,它为该主题添加了额外的引号。下面的请求就像一个魅力
{
"message":{
"topic":"news",
"data":{
"title":"Hellow World",
"message":"This is the Topic Message",
"type1":"100",
"type2":"abc"
}
}
}
【问题讨论】:
标签: android firebase push-notification firebase-cloud-messaging