繁体   English   中英

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

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

为了加快我的开发/测试速度,我尝试开始使用 Cloud Functions:shell,而不是在每次进行微小更改时部署 --only 功能。

不过,我收到“无效凭据”错误。

这是一个基本的工作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);

以下是我在 CLI 中从 shell 调用 function 的方法:

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

Output 是“嗨!” 写入控制台,这很好。

问题是当我尝试使用以下 function 中的 admin.database() 时:

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

这是 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'"

我已经阅读了'302 found' code ad 'invalid-credentials' 的文档,但这并没有告诉我太多关于解决问题的信息,所以我开始想知道我是否需要一个服务帐户来初始化 Admin SDK,但是没有意义,因为当我运行部署时,功能无缝运行,我可以读取/写入实时数据库/从实时数据库读取/写入。

这里有什么问题?

您是否尝试设置GOOGLE_APPLICATION_CREDENTIALS环境变量? 它可能会解决您的问题: https://firebase.google.com/docs/functions/local-emulator

在这种情况下,使用 Cloud Functions Shell 时查看此使用服务帐户凭据可能会有所帮助。

暂无
暂无

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

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