【发布时间】:2020-10-31 13:58:37
【问题描述】:
Firebase 配置
我的 Firebase 项目中有这两个服务帐号
1) project-id@appspot.gserviceaccount.com
2) firebase-adminsdk-8myok@project-id.iam.gserviceaccount.com
在 IAM 配置中,第一个帐户具有“编辑者”角色,第二个帐户具有:
1) Administrator Service Agent for the Administrator SDK
2) Service account token creator
3) Storage Manager
我的云函数的代码就是:
const functions = require("firebase-functions");
const admin = require("firebase-admin");
const sizeOf = require("image-size");
const url = require("url");
const https = require("https");
// Initialize App
admin.initializeApp({
databaseURL: "https://project-id.firebaseio.com",
storageBucket: "project-id.appspot.com",
});
// Create Storage
const storage = admin.storage();
// Create Firestore
const firestore = admin.firestore();
// Validate image dimensions
exports.validateImageDimensions = functions
.region("us-central1")
// Increased memory, decreased timeout (compared to defaults)
.runWith({ memory: "2GB", timeoutSeconds: 120 })
.https.onCall(async (data, context) => {
// Get the image's owner
const owner = context.auth.token.uid;
// Get the image's info
const { id, description, location, tags, time } = data;
// Get the photos' bucket
const bucket = storage.bucket("photos");
...
而我的服务帐户只是 Firebase 控制台上生成的 .json:
Project Configuration > Service Accounts > Firebase Admin SDK -> Generate Private Key
错误
调用函数时出现此错误:
{
"error": {
"code": 404,
"message": "The requested project was not found.",
"errors": [
{
"message": "The requested project was not found.",
"domain": "global",
"reason": "notFound"
}
]
}
}
有什么想法吗?
【问题讨论】:
-
只是为了确认一下,您在使用第一个或第二个服务帐户时收到此错误?
-
第一。知道我已经给它“编辑”角色,但仍然失败。编辑角色是谷歌云创建此服务帐户时赋予的默认角色。 (我以前误删了)
标签: firebase google-cloud-platform google-cloud-firestore google-cloud-functions firebase-admin