Python 如何在 Cloud Function 和 Firestore DB 之间建立连接?
how to Establish connection between Cloud Function And Firestore DB in Python?
I want to Import the data from my firestore to Cloud Function and do some manipulation in python language. So far I have studied the documentation but it is not much helpful Documentation.
The problem is this-->
import firebase_admin
from firebase_admin import credentials
from firebase_admin import firestore
//Use a service account
**cred = credentials.Certificate('path/to/serviceAccount.json')**
firebase_admin.initialize_app(cred)
db = firestore.client()
Where will I store this file "path/to/serviceAccount.json", I can only see two files on my cloud function called Main.py and requirement.
您显示的代码片段适用于在本地 server/your 机器上使用 firestore 库。在这种情况下,您必须为要用于请求的服务帐户创建一个 JSON 密钥文件。我建议您首先熟悉 service accounts。还有一个关于键的部分。
但是,你是运行云函数中的代码。在这种情况下,您在创建云函数时指定为 运行时服务帐户 的服务帐户默认用于任何请求,您不必使用密钥文件。所以你基本上可以只启动 here 并且默认情况下 Client
将使用该服务帐户进行初始化。 重要提示: 服务帐户必须具有对 use/query firestore 的相应权限(参见我的第一个 link 服务帐户权限)。
I want to Import the data from my firestore to Cloud Function and do some manipulation in python language. So far I have studied the documentation but it is not much helpful Documentation.
The problem is this-->
import firebase_admin
from firebase_admin import credentials
from firebase_admin import firestore
//Use a service account
**cred = credentials.Certificate('path/to/serviceAccount.json')**
firebase_admin.initialize_app(cred)
db = firestore.client()
Where will I store this file "path/to/serviceAccount.json", I can only see two files on my cloud function called Main.py and requirement.
您显示的代码片段适用于在本地 server/your 机器上使用 firestore 库。在这种情况下,您必须为要用于请求的服务帐户创建一个 JSON 密钥文件。我建议您首先熟悉 service accounts。还有一个关于键的部分。
但是,你是运行云函数中的代码。在这种情况下,您在创建云函数时指定为 运行时服务帐户 的服务帐户默认用于任何请求,您不必使用密钥文件。所以你基本上可以只启动 here 并且默认情况下 Client
将使用该服务帐户进行初始化。 重要提示: 服务帐户必须具有对 use/query firestore 的相应权限(参见我的第一个 link 服务帐户权限)。