I need to connect with firestore database using python, but I don't want to use Service Account Key. Can I connect using python just with ProjectId and ApiKey?
Using javascript I can do that just like that:
firebase.initializeApp({
apiKey: process.env.REACT_APP_FIREBASE_API_KEY,
projectId: process.env.REACT_APP_FIREBASE_PROJECT_ID,
});
But I can't do that using Python I get this error:
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.
This is my code right now:
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()