2017-05-17 221 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'。