配置firebase实时数据库

时间:2018-06-11 09:42:53

标签: node.js firebase firebase-realtime-database firebase-authentication actions-on-google

我已经使用firebase功能初始化了firebase并进行了部署。我正在使用履行,我不使用单独的服务器。我只使用firebase,即。我已经开发了javascript代码并部署在firebase本身。

现在我想用这个项目配置firebase实时数据库。

我可以使用下面的示例代码吗?

var admin = require("firebase-admin");

// Fetch the service account key JSON file contents
var serviceAccount = require("path/to/serviceAccountKey.json");

// Initialize the app with a service account, granting admin privileges
admin.initializeApp({
  credential: admin.credential.cert(serviceAccount),
  databaseURL: "https://databaseName.firebaseio.com"
});

// As an admin, the app has access to read and write all data, regardless of Security Rules
var db = admin.database();
var ref = db.ref("restricted_access/secret_document");
ref.once("value", function(snapshot) {
  console.log(snapshot.val());
});

我几乎没有问题:

  1. 从哪里开始配置firebase实时数据库?
  2. 如何获取文件“serviceAccountKey.json”?因为,我没有使用单独的服务器。
  3. 如何获取数据库URL?
  4. 数据库之前是否需要进行OAuth配置?

1 个答案:

答案 0 :(得分:1)

我相信自从V1以来你不需要配置管理员,因为它需要配置形式服务器自己查看此链接以获取更多信息https://firebase.google.com/docs/functions/beta-v1-diff#new_initialization_syntax_for_firebase_admin