firebase - 如何解决“错误:无法使用可用凭据初始化 Google Cloud Firestore 客户端。”?
问题描述
尝试使用我的 Firebase Cloud Functions 部署时,Firebase deploy
出现以下错误:
Error: Error occurred while parsing your function triggers.
Error: Failed to initialize Google Cloud Firestore client with the available credentials. Must initialize the SDK with a certificate credential or application default credentials to use Cloud Firestore API.
at FirebaseFirestoreError.FirebaseError [as constructor] (/functions/node_modules/firebase-admin/lib/utils/error.js:42:28)
at new FirebaseFirestoreError (/functions/node_modules/firebase-admin/lib/utils/error.js:220:23)
at getFirestoreOptions (/functions/node_modules/firebase-admin/lib/firestore/firestore.js:96:11)
at initFirestore (/functions/node_modules/firebase-admin/lib/firestore/firestore.js:105:19)
at new FirestoreService (/functions/node_modules/firebase-admin/lib/firestore/firestore.js:43:32)
at /functions/node_modules/firebase-admin/lib/firebase-app.js:261:20
at FirebaseApp.ensureService_ (/functions/node_modules/firebase-admin/lib/firebase-app.js:351:23)
at FirebaseApp.firestore (/functions/node_modules/firebase-admin/lib/firebase-app.js:259:28)
at FirebaseNamespace.fn (/functions/node_modules/firebase-admin/lib/firebase-namespace.js:327:45)
at Object.<anonymous> (/functions/lib/users.js:6:27)
我怎样才能避免这种情况?
解决方案
1.解决方案
更新
您可以通过执行简单地更新您的 Firebase 管理员npm i firebase-admin
。感谢@samthecodingman 提供信息。
以前的
解决此问题的一种方法是通过执行npm i firebase-admin@8.9.0
因为它似乎只影响版本来降级 Firebase 管理员的版本8.9.1
。
2.解决方案
解决问题的另一种方法是export GOOGLE_APPLICATION_CREDENTIALS="path/to/key.json"
在命令行中运行。您可以按照以下步骤获取 Google 应用程序凭据:
- 打开 Google Cloud Console 的服务帐户窗格。
- 确保选择了 App Engine 默认服务帐户,并使用右侧的选项菜单选择创建密钥。
- 出现提示时,选择 JSON 作为密钥类型,然后单击创建。
有关更多信息,请参阅 Firebase文档
推荐阅读
- asp.net - 如何在全局范围内使用 OverrideAuthorization 来授权 MVC 中的特定角色(而不强制对整个程序进行授权)?
- python-3.x - 如何在 tkinter gui 中删除循环依赖
- c++ - 闪存卡游戏的数字添加不正确?Cpp
- java - 线程“主”java.lang.ArrayIndexOutOfBoundsException 中的异常:索引 1 超出长度 1 的范围
- python - seaborn FutureWarning:将以下变量作为关键字参数传递:x,y
- django - 在 ForeignKey Django 模型中获取显示选择
- vb.net - 如果不满足某些条件,则跳过文本文件 vb.net
- flutter - Retrofit Flutter 不生成model-json转换方法
- flurry - #flurry 仪表板是否存在最近或已知的问题?
- c++ - 将类(mixin)的功能与模棱两可的调用结合起来