android - 如何使用 http 向所有设备发送 fcm 通知?
问题描述
我想向所有设备发送通知,我该如何使用 fcm http 来做到这一点。
我使用的端点:https://fcm.googleapis.com/fcm/send
这是我尝试过的。
{
notification: {
title: "Daily motivation!",
body: "The greatest glory in living lies not in never falling, but in rising every time we fall. - Nelson Mandela",
tag: "DAILY_QUOTE"
},
collapse_key: "dailyquote"
};
我也试过条件:
{
notification: {
title: "Daily motivation!",
body: "The greatest glory in living lies not in never falling, but in rising every time we fall. - Nelson Mandela",
tag: "DAILY_QUOTE"
},
condition: "!('nothingreally' in topics)"
collapse_key: "dailyquote"
};
标题:
{
"Content-Type": "application/json",
"Authorization": "key=" + myApiKey
}
虽然,当我发送到特定的时候它工作得很好registration IDs
,但是当我想发送到所有设备时它就不起作用了。我错过了什么吗?
解决方案
您可以按照以下方法。
获取设备的 FCM 令牌。
在某个主题下注册(订阅)FCM 代币(例如 - daily-motivational-quotes)。
向主题发送通知(例如 - daily-motivational-quotes)
https://fcm.googleapis.com/v1/projects/mobiquity-fcm/messages:send
{
"message": {
"topic": "daily-motivational-quotes",
"notification": {
"title": "Daily motivation!",
"body": "The greatest glory in living lies not in never falling, but in rising every time we fall. - Nelson Mandela",
}
}
您可以在一个主题下注册多个设备。
推荐阅读
- angular - 使用 Angular 进行分页 - 电影数据库 API
- spring - @requestMapping 和 @requestParam 的属性参数的区别
- java - 如何从 Microsoft Translator 获取翻译组?
- java - 如何通过 Spring MVC 向客户端提供动态变化的照片?
- ios - 如何使用完成块,然后将数据放入 TableView 单元格?
- reactjs - 反应导航:与状态持久性的深度链接在网络上不起作用
- java - 在处理中运行时,我的草图不会显示任何内容
- python - Pandas 计算多列中的匹配项
- javascript - 如何展示单品?
- powershell - Powershell:从网页中提取地址