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

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

问题描述

当尝试使用 http 触发器运行我的 firebase 云功能时,我不断收到此错误,但只是间歇性的:

错误:获取应用程序默认凭据时出现意外错误:读取 ECONNRESET

有一些不相关的 ECONNRESET/firebase SO 答案没有提供解决方案:

然后点击服务帐户标签:

然后点击生成新的私钥"下载文件.

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

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 

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

解决方案

Problem:

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):

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

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

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.

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

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

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