查看 2022 年 Google I/O 大会上介绍的 Firebase 新动态。
了解详情
开始将 Firebase 与现有 Google Cloud 项目搭配使用
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
Firebase 项目是一个启用了一些额外 Firebase 特定配置和服务的 Google Cloud 项目。这通常称为向 Google Cloud 项目“添加 Firebase”。本页面介绍如何“添加 Firebase”以及一些常见问题解答 (FAQ)。
向 Google Cloud 项目添加 Firebase 后,Firebase 会自动启用多个 API 并创建服务账号,以简化所有 Firebase 服务和接口的使用。Firebase 还会在 Google Cloud 控制台的“标签”页面中向您的项目添加 firebase:enabled
标签。详细了解“添加 Firebase”后会发生什么情况。
Firebase 项目与 Google Cloud 项目之间的关系
由于 Firebase 项目也是 Google Cloud 项目,因此:
您可以在 Firebase 控制台以及 Google Cloud 控制台和 Google API 控制台中访问项目并与其进行交互。
您可以使用 Firebase CLI、gcloud CLI 和 Google 提供的任何 Terraform 资源与项目进行交互。
您可以在项目中同时使用 Firebase 和 Google Cloud 的产品与 API。
项目的 IAM 权限和角色会在 Firebase 和 Google Cloud 之间共享。项目成员(即主账号)对您的 Google Cloud 项目拥有的任何访问权限也将适用于您的 Firebase 项目(反之亦然)。
项目的结算设置会在 Firebase 和 Google Cloud 之间共享。如果您的 Google Cloud 项目已启用结算功能,那么您的 Firebase 项目将采用 Firebase 的随用随付 Blaze 定价方案。
项目的唯一标识符(如项目编号和项目 ID)会在 Firebase 和 Google Cloud 之间共享。
任何应用于 Google Cloud 项目的资源层次结构(例如组织、文件夹等)也将应用于 Firebase 项目。
删除项目会将其从 Firebase 和 Google Cloud 中删除。
删除或修改项目中的资源或数据会影响到 Firebase 和 Google Cloud。
如何向现有 Google Cloud 项目添加 Firebase
您可以使用以下任一选项向现有 Google Cloud 项目“添加 Firebase”。确保您拥有向 Google Cloud 项目添加 Firebase 所需的权限。
请注意,向现有 Google Cloud 项目“添加 Firebase”后,您将无法撤消此操作(也就是说,您无法完全从 Google Cloud 项目中“移除 Firebase”)。如需了解详情,请参阅此常见问题解答。
Firebase 控制台
前往 Firebase 控制台。
使用可让您访问现有 Google Cloud 项目的同一 Google 账号登录。
点击创建项目。
在页面底部,点击已有 Google Cloud 项目了?链接。
在文本字段中,开始输入现有项目的项目 ID,然后从显示的列表中选择该项目。
点击打开项目。
如果系统提示,请接受 Firebase 条款。
按照屏幕上的说明“添加 Firebase”并设置 Firebase 项目。
请注意,启用 Google Analytics 是可选操作。
Firebase CLI
如果您尚未安装 Firebase CLI,请先安装。
使用可让您访问现有 Google Cloud 项目的同一 Google 账号登录。
运行以下命令:
firebase projects:addfirebase
当系统提示时,从显示的列表中选择现有 Google Cloud 项目。
在现有 Google Cloud 项目中启用 Firebase Management API (firebase.googleapis.com
)。
使用 google_firebase_project
资源为项目启用 Firebase 服务。
如需详细了解如何使用 Firebase 和 Terraform,请参阅使用入门:将 Terraform 与 Firebase 搭配使用。
常见问题解答和问题排查
是否必须接受 Firebase 服务条款才能开始使用 Firebase?
如需在 Google Cloud 项目中访问和使用 Firebase 的所有功能,您需要接受 Firebase 服务条款。 如需向现有 Google Cloud 项目“添加 Firebase”,您也需要接受 Firebase 条款。
无论您有权访问多少个项目,只需针对您的 Google 账号接受一次 Firebase 条款。您接受条款时,仅代表您接受这些条款适用于您的 Google 账号;不代表所有项目成员在项目级接受这些条款。
您可以在 Firebase 控制台中使用以下任一选项接受 Firebase 条款。出现提示时,接受条款。
使用 Firebase 控制台创建新的 Firebase 项目。
在 Firebase 控制台中打开现有的 Firebase 项目(例如,有人邀请您成为项目成员,即主账号)。
在 Firebase 控制台中打开现有的 Google Cloud 项目,并向该项目添加 Firebase。
需要哪些权限才能“添加 Firebase”?
如需向现有 Google Cloud 项目“添加 Firebase”,项目成员(即主账号)必须拥有以下 IAM 权限:
firebase.projects.update
resourcemanager.projects.get
serviceusage.services.enable
serviceusage.services.get
默认情况下,IAM 角色“Editor”和“Owner”包含这些权限。
添加 firebase:enabled
标签是否足以添加 Firebase?
所有 Firebase 项目在 Google Cloud 控制台的“标签”页面中都有一个 firebase:enabled
标签。
不过,仅将 firebase:enabled
标签手动添加到项目标签列表中并不会为您的 Google Cloud 项目启用特定于 Firebase 的配置和服务。要做到这一点,您需要使用 Firebase 控制台添加 Firebase(或者,对于高级用例,您需要使用 Firebase CLI、Firebase Management REST API 或 Terraform)。
向现有 Google Cloud 项目“添加 Firebase”后会发生什么情况?
Firebase 项目是一个启用了一些额外 Firebase 特定配置和服务的 Google Cloud 项目。因此,当您向现有 Google Cloud 项目“添加 Firebase”后,Firebase 会执行以下操作,以简化所有 Firebase 服务和接口的使用:
是否可以从项目中“移除 Firebase”?
向现有 Google Cloud 项目“添加 Firebase”后,您将无法撤消此操作(也就是说,您无法完全从 Google Cloud 项目中“移除 Firebase”)。
“添加 Firebase”过程会启用可用于其他 Google Cloud 功能的 API 和后端服务。停用所有这些已启用的服务可能会因依赖关系而导致意外后果。
不过,如果您愿意,可以手动停用所有 API,并删除在“添加 Firebase”时自动启用和创建的标签、API 密钥和服务账号。
是否可以针对现有 Google Cloud 项目阻止“添加 Firebase”操作?
虽然您实际上无法阻止向现有 Google Cloud 项目“添加 Firebase”,但您可以执行以下操作:
限制拥有“添加 Firebase”所需的 IAM 权限 firebase.projects.update
的项目成员(即主账号)。
后续步骤
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-03-15。
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["没有我需要的信息","missingTheInformationINeed","thumb-down"],["太复杂/步骤太多","tooComplicatedTooManySteps","thumb-down"],["内容需要更新","outOfDate","thumb-down"],["翻译问题","translationIssue","thumb-down"],["示例/代码问题","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-03-15。"],[],[]]