【问题标题】:Firebase Admin SDK Error Requested Project Not FoundFirebase Admin SDK 错误 未找到请求的项目
【发布时间】: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


【解决方案1】:

您好像使用的是没有角色的服务帐号,建议您看看这个documentation

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

提醒一下,我建议您检查声明 https://project-id.firebaseio.com 的 URL 是否设置无误,当我尝试输入 URL 时收到消息:“未找到”。

如果这种行为仍然存在,我认为您可以尝试按照建议的方式报告您的使用情况here

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-12-21
  • 2017-11-22
  • 2020-11-27
  • 1970-01-01
  • 2014-11-06
  • 2017-10-18
  • 1970-01-01
相关资源
最近更新 更多