小编Mic*_*kop的帖子

Google Firebase:使用 Python 获取、更新或创建文档

我无法使用 Python 在 Google Firebase (Cloud Firestore) 数据库中获取、更新或创建文档。

我拥有的:

A) 包含集合和文档的数据库(在网络上手动插入):在此处输入图片说明

B) 凭证 JSON 文件另存为test.jsonpath/to/serviceKey.json在文档中经常调用),如下所示(已编辑):

{
  "type": "service_account",
  "project_id": "test-6f02d",
  "private_key_id": "fffca ... 5b7",
  "private_key": "-----BEGIN PRIVATE KEY-----\n ... 1IHE=\n-----END PRIVATE KEY-----\n",
  "client_email": "test-admin@test-6f02d.iam.gserviceaccount.com",
  "client_id": "112 ... 060",
  "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/ ... .gserviceaccount.com"
}
Run Code Online (Sandbox Code Playgroud)

此用户具有角色Owner

C)firebase_admin 安装(使用virtualenv,pip),我可以这样做:

{
  "type": "service_account",
  "project_id": "test-6f02d",
  "private_key_id": "fffca ... 5b7",
  "private_key": "-----BEGIN PRIVATE KEY-----\n ... 1IHE=\n-----END PRIVATE KEY-----\n",
  "client_email": "test-admin@test-6f02d.iam.gserviceaccount.com",
  "client_id": "112 ... …
Run Code Online (Sandbox Code Playgroud)

python firebase firebase-admin google-cloud-firestore

2
推荐指数
1
解决办法
9103
查看次数