【发布时间】:2016-10-28 00:52:19
【问题描述】:
我将 Firebase 与 Android 应用(身份验证、数据库和通知)结合使用。
我正在尝试从外部服务器(在 nodejs 中)发送通知,以便用户可以向另一个用户发送通知。
因此,android 应用程序会记住一个 UserId 列表(与 Firebase Auth 相同的 id),然后将此列表发送到 nodejs 服务器。
使用此列表,服务器会联系 url 'https://fcm.googleapis.com/fcm/send',但 Firebase 会返回一个 InvalidRegistration,因为我发送的是 userId 列表,而不是由 firebase 通知创建的注册令牌列表。
我应该记住这些令牌还是有办法使用用户 ID 发送通知?
(当我尝试使用令牌列表时,它当然可以工作。)
var requestData = {
"registration_ids": userIds, //Problem is here
"data": {
"message": "A message"
}
};
request({
url: "https://fcm.googleapis.com/fcm/send",
method: "POST",
json: true,
headers: {
"Authorization": "key=firebaseKey",
"content-type": "application/json",
},
json: requestData
},
function(err, response, body) {
});
【问题讨论】:
-
您必须保存每个用户的注册令牌,以便从服务器发送通知。
-
好的,谢谢!文档中的这句话让我不这么认为“请注意,注册令牌必须保密。”
-
在您的数据库、服务器或任何秘密永久秘密容器中保密。
标签: android node.js notifications firebase