UA *_*DEV 2 push-notification firebase firebase-cloud-messaging
尝试向 FCM 服务器进行身份验证时出错。确保用于验证此 SDK 的凭据具有适当的权限。有关设置说明, 请参阅https://firebase.google.com/docs/admin/setup在此处输入图片说明
Pes*_*san 91
为了解决这个问题,我采取了以下步骤:
Abh*_*ire 17
默认情况下,Firebase 使用 Firebase Cloud Messaging API (V1),因此您需要使用此 api 而不是旧版 API
对于 Firebase 云消息 API (V1):
const data = {
message: {
token: registrationToken,
notification: {
title: "Notification Title",
body: "Notification Body ",
},
data: {
Nick: "Mario",
Room: "PortugalVSDenmark",
},
},
};
admin.messaging().send(data.message);
Run Code Online (Sandbox Code Playgroud)
对于 Cloud Messaging API(旧版) 1.首先转到 Google Cloud Platform Dashboard 并启用 Cloud Messaging Service 2.然后您可以像这样使用:
var payload = {
notification: {
title: "This is a Notification",
body: "This is the body of the notification message.",
},
};
var options = {
priority: "high",
};
var registrationToken ="your device token";
admin
.messaging()
.sendToDevice(registrationToken, payload, options)
.then(function (response) {
console.log("Successfully sent message:", response);
})
.catch(function (error) {
console.log("Error sending message:", error);
});
Run Code Online (Sandbox Code Playgroud)
建议使用 Firebase Cloud Messaging API (V1),而不是 Cloud Messaging API(旧版)
小智 9
就我而言,按照Abhimanyu的解决方案生成新密钥仍然无法解决问题。
经过 5 个小时的挖掘,我找到了 Google 没有为我的项目激活此 API 的根本原因!!!!
激活云消息权限后就可以了。
我刚刚遇到这个问题,对我来说,这是因为我使用的是模拟器。模拟器生成的 FCM 令牌对 firebase 云消息传递无效,并且它抛出了这个错误。
我把我的admin.messaging().sendToDevice()变成了一个try catch,它工作正常。
我不知道它是否仅向有效令牌发送通知,或者它是否完全忽略了所有令牌
| 归档时间: |
|
| 查看次数: |
1841 次 |
| 最近记录: |