Firebase云功能:错误:获取应用程序默认凭据时发生意外错误:读取ECONNRESET [英] Firebase Cloud Functions: Error: Unexpected error while acquiring application default credentials: read ECONNRESET

查看:70
本文介绍了Firebase云功能:错误:获取应用程序默认凭据时发生意外错误:读取ECONNRESET的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当尝试使用http触发器运行firebase云功能时,我一直出现此错误,但只是间歇性地出现:

When trying to run my firebase cloud function with http trigger, I kept getting this error but only intermittently:

Error: Unexpected error while acquiring application default credentials: read ECONNRESET 

有一些不相关的ECONNRESET/firebase SO答案没有提供解决方案: Firebase存储&云功能-ECONNRESET

There are some unrelated ECONNRESET/firebase SO answers that provided no solution: Firebase Storage & Cloud Functions - ECONNRESET

推荐答案

问题:

要初始化我的功能,我使用了:

To initialize my functions I was using:

const functions = require('firebase-functions');
const admin = require('firebase-admin');    

admin.initializeApp(functions.config().firebase);

解决方案(至少对我来说):

Solution (for me at least):

我必须使用我的Google服务帐户凭据:

I had to use my Google service account credentials:

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

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

要获取Firebase项目名称,请检查Firebase项目控制台(A)的左上角.

To get the firebase project name check the top left corner of your firebase project console (A) .

要下载服务帐户JSON文件,请单击Firebase控制台左上方的(B)齿轮图标,然后单击(C)项目设置:

To Download the service account JSON file click on the (B) gear icon in the top left of the firebase console then click (C) project settings:

然后单击服务帐户"标签:

Then click the service accounts tab:

然后单击生成新私钥以下载文件.

Then click the "Generate New Private Key to download the file.

然后您可以将JSON文件移动到项目函数文件夹中,并按照上面的代码片段所示将其导入.

You can then move the JSON file into your project functions folder and import it as shown in the code snippet above.

这篇关于Firebase云功能:错误:获取应用程序默认凭据时发生意外错误:读取ECONNRESET的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆