問題解決了! 由於舊版本。admin.messaging不是函數
我盡我所能,但無法找到任何解決方案在stackoverflow /谷歌/ firebase。
我在linux服務器上構建node.js,並且不能在firebase中使用Cloud Messaging的功能。 我可以成功連接到Firebase上的數據庫。 但我無法使用雲消息傳遞服務。
我在編碼方面很新,所以請告訴我是否有任何基本錯誤。
我的一些代碼上的Node.js:
var admin = require("firebase-admin");
var serviceAccount_2 = require("/home/____________.json");
var app_V2 = admin.initializeApp({
credential: admin.credential.cert(serviceAccount_2),
databaseURL: "https://_______.firebaseio.com"
}, "myapp");
var payload = {
notification: {
title: "This is Title",
body: "This is Msg body"
}
};
var topic = "some_topic";
admin.messaging().sendToTopic(topic, payload)
.then(function(response) {
console.log("Successfully sent message:", response);
})
.catch(function(error) {
console.log("Error sending message:", error);
});
我試了很多時間,但仍然有同樣的錯誤。
FIREBASE WARNING: Exception was thrown by user callback. TypeError: admin.messaging is not a function
TypeError: admin.messaging is not a function
我嘗試使用上 https://firebase.google.com/docs/cloud-messaging/admin/send-messages#send_to_a_topic 相同的代碼,但仍然有同樣的錯誤。
你可以運行'npm version firebase'並告訴它回報了什麼? –
我無法構建一個「package.json」,我無法使用_「npm version firebase」來檢查它_ 但我的版本應該是[email protected]_ –