无法使用 firebase 控制台发送数据消息
Unable to send data message using firebase console
我正在使用 firebase 控制台,并且只能使用它发送通知消息。
有没有办法使用相同的方法发送数据消息?
Firebase 通知控制台只能用于发送通知消息。它不能用于发送数据消息。
参见message types in the Firebase documentation中的table:
Notification message
Use scenario: FCM automatically displays the message to end-user devices on behalf of the client app. Notification messages have a predefined set of user-visible keys.
How to send:
Use your app server and FCM server API: Set the notification key. May have optional data payload. Always collapsible.
Use the Notifications console: Enter the Message Text, Title, etc., and send. Add optional data payload by providing Custom data in the Notifications console. Always collapsible.
Data message
Use scenario: Client app is responsible for processing data messages. Data messages have only custom key-value pairs.
How to send:
- Use your app server and FCM server API: Set the data key only. Can be either collapsible or non-collapsible.
请看这里:,我的 post 六月。
总之,您需要发送 HTTP POST 请求到 https://fcm.googleapis.com/fcm/send
https://fcm.googleapis.com/fcm/send
Content-Type:application/json
Authorization:key=AIzaSyZ-1u...0GBYzPu7Udno5aA
{ "data": {
"score": "5x1",
"time": "15:10"
},
"to" : "bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1..."
}
您可以使用 Postman(用于测试 http 请求的 rest 客户端)测试通知消息和数据消息。查看屏幕截图:
头球传中:
key:Content-Type, value:application/json
key:Authorization:key=<Server key>
您现在可以通过控制台发送 notification message。注意不同于data messages;通知消息仅在应用程序位于前台时触发 onMessageReceived
回调。
它们位于撰写邮件屏幕上的高级选项选项卡中。
只需展开它并输入您的 key/value 地图。
这些将包含在通知的数据字段中。
我正在使用 firebase 控制台,并且只能使用它发送通知消息。
有没有办法使用相同的方法发送数据消息?
Firebase 通知控制台只能用于发送通知消息。它不能用于发送数据消息。
参见message types in the Firebase documentation中的table:
Notification message
Use scenario: FCM automatically displays the message to end-user devices on behalf of the client app. Notification messages have a predefined set of user-visible keys.
How to send:
Use your app server and FCM server API: Set the notification key. May have optional data payload. Always collapsible.
Use the Notifications console: Enter the Message Text, Title, etc., and send. Add optional data payload by providing Custom data in the Notifications console. Always collapsible.
Data message
Use scenario: Client app is responsible for processing data messages. Data messages have only custom key-value pairs.
How to send:
- Use your app server and FCM server API: Set the data key only. Can be either collapsible or non-collapsible.
请看这里:
总之,您需要发送 HTTP POST 请求到 https://fcm.googleapis.com/fcm/send
https://fcm.googleapis.com/fcm/send
Content-Type:application/json
Authorization:key=AIzaSyZ-1u...0GBYzPu7Udno5aA
{ "data": {
"score": "5x1",
"time": "15:10"
},
"to" : "bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1..."
}
您可以使用 Postman(用于测试 http 请求的 rest 客户端)测试通知消息和数据消息。查看屏幕截图:
头球传中:
key:Content-Type, value:application/json
key:Authorization:key=<Server key>
您现在可以通过控制台发送 notification message。注意不同于data messages;通知消息仅在应用程序位于前台时触发 onMessageReceived
回调。
它们位于撰写邮件屏幕上的高级选项选项卡中。
只需展开它并输入您的 key/value 地图。
这些将包含在通知的数据字段中。