Python中的Firestore模拟器

问题描述

我正在尝试使用 python 3.8 连接到 firestore 模拟器 8.12。我很难找到一种连接方式。我已经从云端的 Firestore 下载了我的密钥。但我正在尝试在本地连接。 local.json 文件在本地连接到模拟器是什么样子的?

import os
import firebase_admin
from firebase_admin import firestore
from firebase_admin import credentials

cred = credentials.ApplicationDefault()
os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = "local.json"

firebase_app = firebase_admin.initialize_app(cred)
db=firestore.client()

data = {
    u'name': u'Los Angeles',u'state': u'CA',u'country': u'USA'
}

# Add a new doc in collection 'cities' with ID 'LA'
db.collection(u'cities').document(u'LA').set(data)

解决方法

从 repo 上的这个 issue 来看,Python Admin SDK 似乎还需要设置 private val checkOnClickListener = View.OnClickListener { view -> view.tag.let { if (it is Int) it else null }?.let { ... } } 环境变量。

FIRESTORE_EMULATOR_HOST