admin.messaging()。sendToDevice()未运行。 NODE.JS

时间:2018-11-22 11:16:14

标签: node.js firebase firebase-cloud-messaging firebase-admin

我正在尝试使用firebase-admin sdk和node.js将通知发送到设备。 admin.messaging()。sendToDevice()未运行。如果还有其他人遇到此问题,请帮助我。

const admin = require("firebase-admin");

let serviceAccount = require("./cloudmessaging-XXXX-firebase-adminsdk-7rsej-15465a00ba.json");


if (!admin.apps.length) {
    admin.initializeApp({
    credential: admin.credential.cert(serviceAccount),
    databaseURL: "https://cloudmessaging-XXXX.firebaseio.com"
    });
}

let registrationToken = regToken;

let payload = {
    notification: {
      title: "Account Deposit",
      body: "A deposit to your savings account has just cleared."
    }
  };

let options = {
    priority: "high",
    timeToLive: 60 * 60 *24
};

admin.messaging().sendToDevice(registrationToken, payload, options)
.then(function(response) {
   console.log("Successfully sent message: ", response)
})
.catch(function(err) {
   console.log("Error occured", err)
})

0 个答案:

没有答案