messaging.sendMulticast 不是函数

messaging.sendMulticast is not a function

当我尝试向设备发送消息时出现上述错误:

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

var serviceAccount = require("./configs.json");

admin.initializeApp({
    credential: admin.credential.cert(serviceAccount),
    databaseURL: "https://pushmessage-bd1eb.firebaseio.com"
});

const db = admin.firestore();
exports.getUsers = functions.https.onRequest(async (req, res) => {
    db.collection("users")
        .get()
        .then(snapshot => {
            const messaging = admin.messaging();
            let registrationTokens = [];
            snapshot.forEach(doc => {
                let id = doc.id;

                registrationTokens.push(id);
            });
            console.log(registrationTokens);

            // process the tokens
            const message = {
                data: { title: "Testing", body: "Test" },
                tokens: registrationTokens
            };

            messaging.sendMulticast(message).then(response => {
                console.log(
                    response.successCount + " messages were sent successfully"
                );
            });
        });
});

sendMulticast 直到最近才被引入到 Firebase Admin SDK 中。尝试将您的 firebase-admin 依赖项升级到最新版本 (npm install firebase-admin@latest)。