当我尝试向主题发送 FCM 通知时,出现以下错误...
Error: An error occurred when trying to authenticate to the FCM servers. Make sure the credential used to authenticate this SDK has the proper permissions.
我正在使用全新生成的服务帐户 key 并正确指向它。我已经确认 key 的路径是正确的。我还为该项目启用了云消息传递。
const { messaging } = require('firebase-admin');
var admin = require('firebase-admin');
console.log(process.cwd());
async function run() {
try {
var serviceAccount = require("/Users/myUser/src/my_project/node_admin/my_project-5617a-firebase-adminsdk-lwpk6-5dad9000e0.json");
const topic = 'all';
admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
});
const payload = {
notification: {
title: "Test1234",
body: "body",
sound: 'test-sound.wav'
}
};
var options = {
priority: "high"
}
await admin.messaging().sendToTopic(topic , payload , options);
} catch (e) {
console.log(e);
}
}
run();
最佳答案
你好,我正在复制代码并运行 --> 它工作正常 所以我想你可以检查文件 auth json 的路径
var serviceAccount = require("/Users/myUser/src/my_project/node_admin/my_project-5617a-firebase-adminsdk-lwpk6-5dad9000e0.json");
祝你好运!
关于node.js - 在 node.js 中使用 Firebase Admin SDK 发送消息时尝试使用 FCM 服务器进行身份验证时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72808612/