当我尝试向设备发送消息时,我收到上述错误:
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 管理员依赖项升级到最新版本 (npm install firebase-admin@latest
(。