未定义Firebase管理员



我想发送消息,但我没有定义这个错误admin。

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);

您似乎正在初始化客户端应用程序中的JavaScriptSDK,并试图从该客户端调用AdminSDK。


正如您在文档中所读到的,"Admin SDK允许您在特权环境中与Firebase进行交互"。

对于"特权环境",文档意味着您完全控制的服务器,或Firebase项目中运行后端代码的云功能(由于它在您自己的项目中,因此您也控制它(。

Firebase云消息的文档也清楚地表明:

Firebase云消息的服务器端由两个零部件:

  • 谷歌提供的FCM后端。您的应用服务器或运行服务器逻辑的其他受信任的服务器环境,如Firebase或其他云的云功能谷歌管理的环境。

  • 您的应用服务器或受信任的服务器环境发送消息请求到FCM后端,然后将消息路由到运行的客户端应用程序在用户的设备上。

还可以查看FCM Architectural Overview上的页面。


因此,您不能使用客户端应用程序中的Admin SDK来发送消息。您需要设置服务器或使用云功能。

最新更新