首页 > 解决方案 > 如何从 python 代码将 Firebase 导出为 JSON?

问题描述

我必须改进使用 Firebase 数据库的 python 项目(需要在数据库中进行更改)。该项目的开发人员消失了,我无法访问 Google 帐户,但数据库仍然响应,我可以访问该 throw 程序。

存储在代码中的东西:

"fire": {
    "type": "service_account",
    "project_id": "...",
    "private_key_id": "...",
    "private_key": "-----BEGIN PRIVATE KEY-----\n ...",
    "client_email": "...@appspot.gserviceaccount.com",
    "client_id": "...",
    "auth_uri": "https://accounts.google.com/o/oauth2/auth",
    "token_uri": "https://oauth2.googleapis.com/token",
    "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
    "client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/...gserviceaccount.com"
}

连接代码:

import firebase_admin

cert = self.data.get('fire')   #parsing JSON into dict
cred = credentials.Certificate(cert)
firebase_admin.initialize_app(cred)
self.db = firestore.client()


我需要将数据库导出为 JSON,这样我就可以创建一个相同的新数据库并进行所需的更改。

标签: pythonfirebasegoogle-cloud-firestorefirebase-admin

解决方案


推荐阅读