【发布时间】:2019-11-15 13:54:27
【问题描述】:
为了加快我的开发/测试速度,我尝试开始使用 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 调用函数的方式:
> firebase functions:shell
> oauth.get("say_hi")
输出是 "HI!" 写入控制台,这很好。
问题是当我尝试在以下函数中使用 admin.database() 时:
app.get("/get_ref", (req, res) => admin.database().ref("users"));
这是输出错误:
"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”代码和“invalid-credentials”的文档,但这并没有告诉我太多关于解决问题的信息,所以我开始想知道我是否需要一个服务帐户来初始化 Admin SDK ,但这没有任何意义,因为当我运行 deploy 时,函数会无缝运行,并且我可以读取/写入 Realtime DB。
这里有什么问题?
【问题讨论】:
标签: node.js firebase express google-cloud-functions