Node.js FCM发送推送至设备组返回';消息/无效收件人';
您好,我正在尝试使用Node.js FCM发送推送至设备组返回';消息/无效收件人';,node.js,firebase,firebase-cloud-messaging,Node.js,Firebase,Firebase Cloud Messaging,您好,我正在尝试使用Firebase云功能通过FCM向如下设备组发送推送通知: // Send a message to the device group corresponding to the provided // notification key. admin.messaging().sendToDeviceGroup(notification_key, payload) .then(function(response) { // See the MessagingDeviceGroup
Firebase云功能
通过FCM
向如下设备组发送推送通知:
// Send a message to the device group corresponding to the provided
// notification key.
admin.messaging().sendToDeviceGroup(notification_key, payload)
.then(function(response) {
// See the MessagingDeviceGroupResponse reference documentation for
// the contents of response.
console.log("Successfully sent message:", response);
})
.catch(function(error) {
console.log("Error sending message:", error);
});
}
控制台返回我:
{ code: 'messaging/invalid-recipient',
message: 'Notification key provided to sendToDeviceGroup() is invalid.' } }
我使用的notification_key
是:const notification_key=“APA91bG09Lqs…rb48dE5hs”代码>
并且是我创建设备组时在响应中返回的通知键
,我注意到您有const notificationKey=“APA91bG09Lqs…rb48dE5hs”代码>但随后有发送到设备组(通知键,有效负载)
。它不应该是sendToDeviceGroup(notificationKey,payload)
?是的……就像那样。。。我写问题的时候不好。。。将编辑以清除错误以及。。。我传递的是创建设备组时收到的值。当我创建一个组时,我收到了一个形式为“APA91bG09Lqs…rb48dE5hs”
->的响应,我最终将其与通知密钥名称一起存储在数据库中作为参考。好的。我对sendToDeviceGroup了解不多,但我真的应该像使用Node.js服务器一样使用它。我用“旧”的方式发送消息,方法如下-。但是你的例子没有理由不起作用。我明白了。。。按照我看到的旧方法,您还需要注册密钥
。。。对吧。。。我在想,也许通过sendToDeviceGroup
我也需要这个。。。所以也许这就是为什么它不起作用。。。