我收到一条错误消息,指出外部网络无法访问,因为我在Firebase的免费层上,这是有道理的。但我认为Firebase服务包含在免费套餐中,因此我应该可以使用FCM。
这是我用于函数的index.js的代码。
var functions = require('firebase-functions');
var admin = require("firebase-admin");
admin.initializeApp(functions.config().firebase);
exports.buttonPress = functions.https.onRequest((req, res) => {
let testToken = "TOKEN";
let payload = {
data: {
type: req.body.type
}
};
admin.messaging().sendToDevice(testToken, payload)
.then(function (response) {
...
})
.catch(function (error) {
...
});
});
答案 0 :(得分:0)
firebaser here
未配置结算帐户。外部网络无法访问,配额严重受限。配置结算帐户以删除这些限制。
此消息现在显示从免费套餐中的项目调用的任何云功能。这并不意味着任何呼叫都被主动阻止,只是他们呼叫外部服务将被阻止此项目。
我们正在查看是否可以删除邮件。
答案 1 :(得分:0)
要通过云功能发送FCM,可以使用以下代码。 检查日志以获取正确的令牌。
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp();
exports.sendNotification = functions.firestore
.document('/users/{documentId}')
.onWrite((change, context) => {
console.log("DOCUMENT ID : " + context.params.documentId);
//Get all data
const payload = {
notification: {
title: 'Test title!',
body: `${userName} sent you a following request.`
// icon: follower.photoURL
}
};
admin.messaging().sendToDevice(followedFCMToken, payload)
.then(function (response) {
console.log("Push response : " + response);
return response
})
.catch(function (error) {
console.error("Error in sending push");
});
});
答案 2 :(得分:-1)
对于免费套餐帐户,Firebase对访问不在Google网络中的外部服务施加了限制。
要找到问题的根本原因,只需转到Firebase控制台并检查您的功能日志。该日志将准确显示您安装的哪些服务正在尝试发出外部HTTP请求。