【发布时间】:2019-02-18 04:28:44
【问题描述】:
我需要使用 python 连接 firestore 数据库,但我不想使用服务帐户密钥。我可以仅通过 ProjectId 和 ApiKey 使用 python 连接吗?
使用 javascript 我可以这样做:
firebase.initializeApp({
apiKey: process.env.REACT_APP_FIREBASE_API_KEY,
projectId: process.env.REACT_APP_FIREBASE_PROJECT_ID,
});
但我无法使用 Python 执行此操作,但出现此错误:
self._g_credential, self._project_id = google.auth.default(scopes=_scopes)
File "/home/caique/.local/lib/python2.7/site-packages/google/auth/_default.py", line 306, in default
raise exceptions.DefaultCredentialsError(_HELP_MESSAGE)
google.auth.exceptions.DefaultCredentialsError: Could not automatically
determine credentials. Please set GOOGLE_APPLICATION_CREDENTIALS or
explicitly create credentials and re-run the application.
这是我现在的代码:
import firebase_admin
from firebase_admin import credentials, firestore, auth
cred = credentials.ApplicationDefault()
firebase_admin.initialize_app(cred, {
'projectId': "my-project-id",
'apiKey': "my-api-key"
})
db = firestore.client()
【问题讨论】:
标签: javascript python firebase google-cloud-firestore