我想发送一个消息,但我有这个错误的管理员没有定义。
var firebaseConfig = {
my conig
};
// Initialize Firebase
firebase.initializeApp(firebaseConfig);
setInterval(function(){
// This registration token comes from the client FCM SDKs.
var registrationToken = 'mytoken';
var message = {
data: {
tittle: 'Tarea no Iniciada',
body: 'Todavia no has iniciado tu tarea'
},
token: registrationToken
};
// Send a message to the device corresponding to the provided
// registration token.
admin.messaging().send(message)
.then((response) => {
// Response is a message ID string.
console.log('Successfully sent message:', response);
})
.catch((error) => {
console.log('Error sending message:', error);
});
},3000);
这是我的脚本,我使用javascript而不是node.js。
因为在你的代码中,你正在做
var firebaseConfig = {
my conig
};
// Initialize Firebase
firebase.initializeApp(firebaseConfig);
看来你是在初始化 客户端应用程序中的JavaScript SDK 并试图从该客户端调用Admin SDK。
正如您将在 文件在这里,"Admin SDK可以让你与Firebase进行交互。特权环境".
文档中的 "特权环境 "指的是你完全控制的服务器,或者你的Firebase项目中运行后端代码的云功能(你也控制,因为它在你自己的项目中)。
该 文件 对于Firebase云消息,也明确指出。
Firebase Cloud Messaging的服务器端由两部分组成。
Google提供的FCM后端。 你的应用服务器或你的服务器逻辑运行的其他可信服务器环境,如Cloud Functions for Firebase或其他由Google管理的云环境。
您的应用服务器或受信任的服务器环境 向FCM后台发送消息请求,然后将消息路由到用户设备上运行的客户端应用程序。
也可以看一下 FCM建筑概述.