Firebase FCM错误:“InvalidRegistration”

目前,我正尝试使用FCMFirebase Cloud Functions的帮助下向Device Group发送PushNotification ,但一旦发送通知,它将返回代码200但会失败:

 SUCCESS response= { multicast_id: 8834986220110966000, success: 0, failure: 1, canonical_ids: 0, results: [ { error: 'InvalidRegistration' } ] } 

这里是我用来发送这个通知的代码…我错过了什么?

 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); }); 

JSON值titlebodysubjectmessage都是String

从云端function发送消息到设备组有一个更简单的方法。 使用admin.messaging()。sendToDeviceGroup() 。 示例代码和说明在本指南中 。

我认为你当前的方法失败,因为groupId提供的组通知密钥有问题。 它应该是创build设备组时返回的string键值。 错误代码在此表中列出。 对于200 / InvalidRegistration它说:

检查您传递给服务器的注册令牌的格式。 确保它与客户端应用程序从注册Firebase通知时收到的注册令牌相匹配。 不要截断或添加其他字符。

注册令牌绑定到一组发件人。 当客户端应用程序注册FCM时,它必须指定允许哪些发件人发送消息。 发送消息到客户端应用程序时,您应该使用其中一个发件人ID。

你需要做的是添加一个http头'project_id'与你的发件人ID。