Firebase将消息发送到多个主题 [英] Firebase Send Message to Multiple Topics
问题描述
我一直在尝试向通过API调用订阅多个主题的用户发送云消息(POST
I've been trying to send cloud messages to users who subscribed to multiple topics through an API call (POST https://fcm.googleapis.com/v1/projects/myproject-b5ae1/messages:send) with the following body:
{
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer MY_ACCESS_TOKEN`
},
body: {
"message": {
"condition": "'cat' in topics || 'dog' in topics",
"notification": {
"title": "Message Title",
"body": "Message Body"
}
}
}
}
我根据 FCM文档.我可以收到类似的回复:
I wrote this config according to the FCM documentation. I can get a response similar to this:
{
"name": "projects/myproject-b5ae1/messages/5735743068807585451"
}
,但任何设备均未收到任何消息.
but no messages were received by any devices.
我已将访问令牌用于其他API,该API可以正常工作.我还知道,FCM文档还为cURL请求提供了不同的正文,我也曾尝试但不起作用.
I've used the access token for other APIs, which works. I'm also aware that the FCM documentation also provided a different body for the cURL request, which I also tried but not working.
奇怪的是,如果我仅在condition
中提供一个主题,则实际上已成功将一条消息发送到订阅的设备.我写错什么了吗?
The weird thing is if I only provide one topic in the condition
, a message is actually successfully sent to subscribed devices. Am I writing something wrong?
我已经在Stackoverflow上引用了其他解决方案,但是一切仍然不起作用:
I've already referenced other solutions on Stackoverflow but everything is still not working:
Firebase API call with multiple topics in condition
How to send FCM Push Notifications to multiple topics
推荐答案
与Firebase支持人员交谈后,他们指出我遇到的问题是他们仍在尝试解决的已知错误.而且还没有修复的具体时间表.
After talking to Firebase Support, they pointed out the problem I'm having here is a known bug they are still trying to fix. And there's no specific timeline for a fix yet.
因此,我的代码没有问题,如果我真的想使用"||"(OR)运算符,则必须自己解决问题.
Therefore, there's no problem with my code and I'll have to figure out a workaround myself if I really want to use the "||"(OR) operator.
我当前的解决方法是通过数据库跟踪订户(因为Firebase不提供订户查询),然后通过查找不同主题的订户联合来自己实现OR条件.
My current workaround is keep track of subscribers with a database (since Firebase doesn't offer subscribers querying), then implement the OR condition myself by finding a union of subscribers to different topics.
P.S.我只是不明白为什么要投票,我实际上在这里发现了一个错误,并在提出问题之前引用了我在SO上可以找到的所有解决方案.
P.S. I just don't get why the downvotes, I actually found a bug here and referenced all the solutions I could found on SO before asking the question here.
这篇关于Firebase将消息发送到多个主题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!