本文介绍了在哪里可以找到"serviceAccountCredentials.json"?对于Firebase管理员?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里是我所需要的在Java上设置Firebase:

Here is said what I need to setup Firebase on java:

FirebaseOptions options = new FirebaseOptions.Builder()
    .setDatabaseUrl("https://databaseName.firebaseio.com")
    .setServiceAccount(new FileInputStream("path/to/serviceAccountCredentials.json"))
    .build();
FirebaseApp.initializeApp(options);

但是我在哪里可以得到 serviceAccountCredentials.json ?

But where can I get serviceAccountCredentials.json ?

更新:我发现该文件似乎应该具有该字段,但是从何处获得该值?

UPDATED: I found that this file seems should have this fields, but where get this values?

{
  "type": "",
  "project_id": "",
  "private_key_id": "",
  "private_key": "",
  "client_email": "",
  "client_id": "",
  "auth_uri": "",
  "token_uri": "",
  "auth_provider_x509_cert_url": "",
  "client_x509_cert_url": ""
}

推荐答案

此链接

要创建文件,您需要转到此链接

To create the file you need to go to this link

https://console.firebase.google.com/project/**YOUR_PROJECT**/settings/serviceaccounts/adminsdk

firebase文档中的报价:

Quote from firebase docs:

  1. 导航到项目设置中的服务帐户标签页.
  2. 点击服务帐户标签的 Firebase Admin SDK 部分底部的生成新私钥按钮.
  1. Navigate to the Service Accounts tab in your project's settings page.
  2. Click the Generate New Private Key button at the bottom of the Firebase Admin SDK section of the Service Accounts tab.

单击按钮后,将包含服务的JSON文件帐户的凭据将被下载.您将需要此在下一步中初始化SDK.

After you click the button, a JSON file containing your service account's credentials will be downloaded. You'll need this to initialize the SDK in the next step.

警告:在以下情况下要格外小心在代码中处理服务帐户凭据.不要提交他们到公共存储库,将其部署在客户端应用程序中,或将其公开可能危及Firebase项目安全性的任何方式.

此文件仅生成一次.如果丢失或泄漏密钥,则可以重复上述说明,为服务创建一个新的JSON密钥帐户.

This file is only generated once. If you lose or leak the key, you can repeat the instructions above to create a new JSON key for the service account.

这篇关于在哪里可以找到"serviceAccountCredentials.json"?对于Firebase管理员?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 03:44