找不到 Firebase Admin SDK 错误请求的项目

Firebase Admin SDK Error Requested Project Not Found

Firebase 配置

我的 Firebase 项目中有这两个服务帐户

1) project-id@appspot.gserviceaccount.com
2) firebase-adminsdk-8myok@project-id.iam.gserviceaccount.com

在 IAM 配置中,第一个账户的角色是“Editor”,第二个账户的角色是:

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"
      }
    ]
  }
}

有什么想法吗?

看来你使用的是没有角色的服务账号,建议你看看这个documentation

此外,这是一个常见问题,您可以检查其他线程 here 并尝试建议的一些解决方法。

作为善意提醒,我建议您检查 URL 声明的 https://project-id.firebaseio.com 是否正确设置,当我尝试进入 URL 时,我收到了消息:“未找到”。

如果此行为持续存在,我认为您可以尝试按照建议报告您的使用情况 here