简体   繁体   English

Cloud Functions Shell 中的 initializeApp() 上的 Firebase 无效凭据 302

[英]Firebase invalid-credential 302 on initializeApp() in Cloud Functions Shell

In order to speed up my development/testing, I am trying to get started with using the Cloud Functions:shell instead of deploying --only functions everytime I make a tiny change.为了加快我的开发/测试速度,我尝试开始使用 Cloud Functions:shell,而不是在每次进行微小更改时部署 --only 功能。

I am getting an 'invalid-credentials' error though.不过,我收到“无效凭据”错误。

This is a basic working index.js file:这是一个基本的工作index.js 文件:

const express = require("express");
const functions = require("firebase-functions");
const admin = require("firebase-admin");
admin.initializeApp();

const app = express();
app.get("/say_hi", (req, res) => console.log("HI!"));
exports.oauth = functions.https.onRequest(app);

Here is how I call the function from the shell in the CLI:以下是我在 CLI 中从 shell 调用 function 的方法:

> firebase functions:shell
> oauth.get("say_hi")

Output is "HI!" Output 是“嗨!” written to the console, which is good.写入控制台,这很好。

The problem is when I try using admin.database() as in the following function:问题是当我尝试使用以下 function 中的 admin.database() 时:

app.get("/get_ref", (req, res) => admin.database().ref("users"));

This is the output error:这是 output 错误:

  "code": "app/invalid-credential",
  "message": "Credential implementation provided to initializeApp() via the 'credential' property failed to fetch a valid Google OAuth2 access token with the following error: 'Error fetching access token: 302 Found'"

I've read the docs for '302 found' code ad 'invalid-credentials', but this doesn't tell me much about solving the issue, so I started wondering if I need a service account to initialize the Admin SDK, but that would not make sense as when I run deploy the functions run seamlessly and I can read/write to/from the Realtime DB.我已经阅读了'302 found' code ad 'invalid-credentials' 的文档,但这并没有告诉我太多关于解决问题的信息,所以我开始想知道我是否需要一个服务帐户来初始化 Admin SDK,但是没有意义,因为当我运行部署时,功能无缝运行,我可以读取/写入实时数据库/从实时数据库读取/写入。

What is the issue here?这里有什么问题?

Have you tried to set the GOOGLE_APPLICATION_CREDENTIALS env variable?您是否尝试设置GOOGLE_APPLICATION_CREDENTIALS环境变量? it probably would solved your issue: https://firebase.google.com/docs/functions/local-emulator它可能会解决您的问题: https://firebase.google.com/docs/functions/local-emulator

and looking at this Use of Service account credentials when using Cloud Functions Shell might be helpful in this case.在这种情况下,使用 Cloud Functions Shell 时查看此使用服务帐户凭据可能会有所帮助。

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

相关问题 Firebase 云消息传递:app/invalid-credential - 无法获取有效的 Google OAuth2 访问令牌 - Firebase Cloud messaging : app/invalid-credential - failed to fetch a valid Google OAuth2 access token Firebase 应用程序初始化失败,凭据无效(firebase 函数初始化) - Firebase app initialization fails with invalid-credential (firebase function initiatlization) 角度通用| firebase-admin | 代码:“ app / invalid-credential” |套接字挂断 - angular-universal | firebase-admin | code: 'app/invalid-credential' |socket hang up on 使用 Firebase CLI shell 测试可调用的云函数 - Testing callable cloud functions with the Firebase CLI shell Firebase Admin INVALID_APP_OPTIONS 错误在 initializeApp() - Firebase Admin INVALID_APP_OPTIONS error at initializeApp() 使用 Nodemailer 和 Firebase Cloud Functions 的错误授权 OAuth2 无效 - Error invalid grant OAuth2 with Nodemailer and Firebase Cloud Functions Firebase Admin SDK-错误:提供了用于初始化App()的凭据实现…无法获取有效的Google OAuth2访问令牌 - Firebase Admin SDK - Error: Credential implementation provided to initializeApp() … failed to fetch a valid Google OAuth2 access token Firebase云功能/ Firestore - Firebase Cloud Functions / Firestore Firebase 云函数路由 - Firebase cloud functions routing Firebase 云功能设置 - Firebase Cloud Functions Setup
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM