Reputation: 512
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.
Upvotes: 1
Views: 864
Reputation: 1305
The code snipped you are showing applies to using the firestore library on a local server/your machine. In that case, you have to create a JSON key file for a service account that you want to use for your requests. I recommend you familiarize yourself with service accounts first. There is also a section on keys.
However, you are running the code in a cloud function. In that case, the service account you specify as runtime service account when creating the cloud function is used for any request as default and you don't have to use a key file. So you can basically just start here and the Client
will be initialized using that service account by default. Important: the service account has to have the respective permissions to use/query firestore (see my first link under service account permissions).
Upvotes: 2