【发布时间】:2020-11-07 07:35:56
【问题描述】:
我正在使用 FCM 进行通知。 FCM 在从 Firebase 数据库创建数据时触发。我收到了第一条消息。之后,就没有收到其他连续的消息了。我在本地环境中运行它。问题是由于以下消息“未配置计费帐户。无法访问外部网络并且配额受到严重限制。配置计费帐户以消除这些限制”或任何其他问题。我是否需要进入接收消息的计费计划。在测试环境中工作,这就是不转向计费计划的原因。如果问题与计费计划无关,有人可以指出代码的任何其他问题。
Firebase 功能日志
6:22:52.133 PM
sendFollowerNotification
Function execution started
6:22:52.133 PM
sendFollowerNotification
Billing account not configured. External network is not accessible and quotas are severely limited. Configure billing account to remove these restrictions
6:22:52.143 PM
sendFollowerNotification
Function execution took 10 ms, finished with status: 'ok'
6:22:52.401 PM
sendFollowerNotification
1 messages were sent successfully
节点js代码
exports.sendFollowerNotification = functions.database.ref('/notification/message/{gId}/{pId}')
.onCreate(async (change, context) => {
//console.log('Group id:', context.params.gId," Push ID:",context.params.pId, "Change",change);
const notificationData = change.val();
var topic = notificationData.topic;
var title = notificationData.title;
var body = notificationData.body;
var registrationTokens = notificationData.tokens;
const message = {
notification: {
title: title,
body: body
},
tokens: registrationTokens,
};
admin.messaging().sendMulticast(message)
.then((response) => {
// Response is a message ID string.
console.log(response.successCount + ' messages were sent successfully');
})
.catch((error) => {
console.log('Error sending message:', error);
});
});
【问题讨论】:
标签: firebase push-notification google-cloud-functions firebase-cloud-messaging