【问题标题】:admin.messaging is not a functionadmin.messaging 不是函数
【发布时间】: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


【解决方案1】:

您很可能安装了旧版本。我能够很好地运行当前版本via RunKit(当然减去适当的凭据)。通过从项目的根目录(运行 npm install firebase-admin 的位置)运行 npm ls firebase-admin 来仔细检查安装的版本。

【讨论】:

  • 我重新安装了所有东西,它现在可以运行了。非常感谢!
猜你喜欢
  • 2018-08-13
  • 1970-01-01
  • 2022-11-21
  • 2018-07-31
  • 2019-02-24
  • 1970-01-01
  • 2017-05-06
  • 2019-12-20
  • 1970-01-01
相关资源
最近更新 更多