2017-05-17 222 views
1

目前我正在试图发送一个PushNotificationDevice Group使用FCMFirebase Cloud Functions的帮助,但一旦通知发出,它的代码200返回,但失败:火力地堡FCM错误:“InvalidRegistration”

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值titlebodysubjectmessageString

回答

2

有从云功能将消息发送到设备组更简单的方法。使用admin.messaging().sendToDeviceGroup()。示例代码和说明在this guide

我认为您的当前方法失败,因为在groupId中提供的组通知密钥有问题。它应该是创建设备组时返回的字符串键值。错误代码列于this table。对于200/InvalidRegistration它说:

Check the format of the registration token you pass to the server. Make sure it matches the registration token the client app receives from registering with Firebase Notifications. Do not truncate or add additional characters.

+0

这实际上并没有回答这个问题,我也从一个节点JS后端使用完全不同的方式获得相同的错误。 – mic

0

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

您需要做的是在您的发件人ID中添加一个http头'project_id'。