使用 firebase 函数配置的 firebase 实时数据库

firebase realtime database configuring with firebase functions

我想用我的 firebase 云功能配置 firebase 实时数据库。

   1)what is "serviceAccountKey.json"?
   2) How to get this file?
   3) did one "serviceAccountKey.json" is enough for all the users using firebase functions?

假设我使用下面的示例

"exports.dbCreate = functions.database.ref('/path').onCreate((event) => {
  const createdData = event.data.val(); // data that was created
   });" 

如何调用 dbCreate 以及我必须在“/path”中提供什么路径? 如何获得 serviceAccountKey.json?

我使用的版本是“"actions-on-google":”^2.0.1”, "firebase-admin": "~5.12.0", "firebase-functions": "^1.0.1", "dialogflow": "^0.1.0", "dialogflow-fulfillment": "^0.4.1","

Firebase 函数是与您的 Firebase 项目交互的服务器端(基于云)脚本。因此,他们需要一个密钥,因为他们可以完全访问您的项目。

你的例子functions.database.ref('/path').onCreate不是你调用的,它是被触发的。

开始使用

a service account to communicate with the Firebase service, and a configuration file with your service account's credentials.

  1. If you don't already have a Firebase project, add one in the Firebase console. The Add project dialog also gives you the option to add Firebase to an existing Google Cloud Platform project.
  2. Navigate to the Service Accounts tab in your project's settings page.
  3. Click the Generate New Private Key button at the bottom of the Firebase Admin SDK section of the Service Accounts tab.