【发布时间】:2017-02-21 09:44:46
【问题描述】:
问题解决了! 因为是旧版本。
我已经尽力了,但在 stackoverflow/google/firebase 上找不到任何解决方案。
我在linux服务器上编译node.js,无法使用firebase中的云消息功能。 我可以成功连接到 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" 检查它,但我的版本应该是 firebase-admin@4.1 .1
标签: node.js firebase firebase-cloud-messaging