anh*_*nho 7 javascript node.js firebase firebase-cloud-messaging
目前我正在试图发送PushNotification到Device Group使用FCM的帮助下Firebase Cloud Functions,但一旦通知发出,它的代码返回200,但失败:
SUCCESS response= {
multicast_id: 8834986220110966000,
success: 0,
failure: 1,
canonical_ids: 0,
results: [ { error: 'InvalidRegistration' } ]
}
Run Code Online (Sandbox Code Playgroud)
这是我用来发送此通知的代码...我缺少什么?
const options = {
method: 'POST',
uri: 'https://fcm.googleapis.com/fcm/send',
headers: {
'Authorization': 'key=' + serverKey,
},
body: {
to: groupId,
data: {
subject: message
},
notification: {
title: title,
body: body,
badge: 1,
},
content_available: true
},
json: true
};
return rqstProm(options)
.then((parsedBody) => {
console.log('SUCCESS response=', parsedBody);
})
.catch((err) => {
console.log('FAILED err=', err);
});
Run Code Online (Sandbox Code Playgroud)
凡JSON值title,body,subject,message是String
就我而言,我正在向主题(“ topics/my-topic”)发送通知。我没有/在主题开头添加任何内容,因此遇到了同样的问题。所以主题应该是/topics/my-topic。
也许这会有所帮助!
有一种更简单的方法可以从云功能向设备组发送消息。使用admin.messaging().sendToDeviceGroup()。本指南中包含示例代码和说明。
我认为您当前的方法失败了,因为 中提供的组通知密钥有问题groupId。它应该是创建设备组时返回的字符串键值。错误代码在此表中列出。对于 200/InvalidRegistration 它说:
检查您传递给服务器的注册令牌的格式。确保它与客户端应用程序通过 Firebase 通知注册收到的注册令牌相匹配。不要截断或添加额外的字符。
| 归档时间: |
|
| 查看次数: |
18572 次 |
| 最近记录: |