为了加快我的开发/测试速度,我尝试着每次使用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")
输出为问题是,当我尝试使用admin.database()时,如以下功能所示:“ HI!”]]写到控制台,这很好。
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”代码广告“无效凭据”的文档,但这并不能告诉我很多有关解决此问题的信息,因此我开始怀疑是否需要一个服务帐户来初始化Admin SDK,但这没有意义,因为当我运行部署时,这些功能可以无缝运行,并且可以读写实时数据库。
这里是什么问题?
为了加快我的开发/测试速度,我尝试每次使用微小功能时,都开始使用Cloud Functions:shell而不是部署--only功能。我得到一个'...
GOOGLE_APPLICATION_CREDENTIALS
env变量?它可能会解决您的问题:https://firebase.google.com/docs/functions/local-emulator