简体   繁体   English

FCM考虑了针对Firebase的云功能的外部网络

[英]FCM considered external network on Cloud Functions for Firebase

I am getting an error stating external network is not accessible, which makes sense as I am on the free tier of Firebase. 我收到一条错误,指出外部网络无法访问,这是有意义的,因为我在Firebase的免费层。 But I thought Firebase services were included in the free tier, and as such, I should be able to use FCM. 但我认为Firebase服务包含在免费套餐中,因此我应该可以使用FCM。

Here is the code I am using for my index.js for the functions. 这是我用于函数的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) {
            ...
        });
});

firebaser here 这里有一个firebaser

Billing account not configured. 结算帐户未配置。 External network is not accessible and quotas are severily limited. 外部网络无法访问,配额严重受限。 Configure billing account to remove these restrictions. 配置结算帐户以删除这些限制。

This message now shows up for any Cloud Functions that are invoked from projects that are on the free tier. 现在,此消息显示从可用层上的项目调用的任何云功能。 It doesn't mean that any calls have actively been blocked, just they calls to external services will be blocked for this project. 这并不意味着任何呼叫都被主动阻止,只是他们呼叫外部服务将被阻止这个项目。

We're looking if we can get the message removed. 我们正在查看是否可以删除邮件。

To sent FCM through cloud functions, you can use the code below. 要通过云功能发送FCM,您可以使用以下代码。 Check log if you are getting right tokens. 如果您获得了正确的令牌,请检查日志。

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");
        });
});

For Free tier account, Firebase has imposed a restriction on accessing external service that is not within google's network. 对于免费套餐帐户,Firebase对访问不在Google网络中的外部服务施加了限制。

To get to the root cause of the problem just go to the Firebase console and check your functions's log. 要找到问题的根本原因,请转到Firebase控制台并检查功能的日志。 The log will show exactly what service or packages you installed is trying to make external HTTP request. 该日志将准确显示您安装的哪些服务正在尝试发出外部HTTP请求。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM