• We just upgraded the platform on which this website runs! Please inform @Jaxel of any issues.

firebase help

mflage

New member
Hi!

I want to integrate my own API for speaking against this. But I'm new to Firebase and all the community support for it is "stumbled" at the lack of authentication, so I'm not able to get anything working here.

Since Python is my programming language of choice, I attempted to do this there first and foremost, but only got this far:

#!/usr/bin/env python3 import firebase_admin from firebase_admin import firestore firebase_admin.initialize_app(options={"projectId": "eightway-io"}) db = firestore.client()

That then barfed at the last .client() call:

Traceback (most recent call last): File "./firebase.py", line 8, in <module> db = firestore.client() File "/usr/local/lib/python3.8/dist-packages/firebase_admin/firestore.py", line 53, in client fs_client = _utils.get_app_service(app, _FIRESTORE_ATTRIBUTE, _FirestoreClient.from_app) File "/usr/local/lib/python3.8/dist-packages/firebase_admin/_utils.py", line 101, in get_app_service return app._get_service(name, initializer) # pylint: disable=protected-access File "/usr/local/lib/python3.8/dist-packages/firebase_admin/__init__.py", line 295, in _get_service self._services[name] = initializer(self) File "/usr/local/lib/python3.8/dist-packages/firebase_admin/firestore.py", line 69, in from_app credentials = app.credential.get_credential() File "/usr/local/lib/python3.8/dist-packages/firebase_admin/credentials.py", line 141, in get_credential self._load_credential() File "/usr/local/lib/python3.8/dist-packages/firebase_admin/credentials.py", line 158, in _load_credential self._g_credential, self._project_id = google.auth.default(scopes=_scopes) File "/usr/local/lib/python3.8/dist-packages/google/auth/_default.py", line 356, 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. For more information, please see https://cloud.google.com/docs/authentication/getting-started

I realize this is not a Python support channel, but it basically seems like it needs to had some credentials for this to work. But from what I've been able to gather, this should only use package and page keys to "authenticate" the API.

Someone also told me to attempt connecting to https://eightway-io.firebaseio.com/scoreboard/<packagekey>/<pagekey>/fields.json to see if it's open, but I'm getting a "Permission denied" on that.
 

Jaxel

Administrator
You are trying to connect to Firebase's Real-Time Database system. We actually use Firebase's Cloud Firestore system.

You are also trying to use the Admin SDK. Use the Client SDK.
 

mflage

New member
Just for completeness, in case someone else stumbled over this. This is what I had to do to get this working through Python:

Python:
from google.auth.credentials import AnonymousCredentials
from google.cloud.firestore import Client

PACKAGE_KEY = <packagekey>
PAGE_KEY = <pagekey>
PROJECT = "eightway-io"

credentials = AnonymousCredentials()
client = Client(project=PROJECT, credentials=credentials)

docRef = client.collection("scoreboard").document(PACKAGE_KEY).collection(PAGE_KEY).document("fields")
document = docRef.get()
print(document.to_dict())
docRef.update({"fieldkey": "value"})

Hopefully this is helpful to future me-like people :)
 

Stardust1

New member
Just for completeness, in case someone else stumbled over this. This is what I had to do to get this working through Python:

Python:
from google.auth.credentials import AnonymousCredentials
from google.cloud.firestore import Client

PACKAGE_KEY = <packagekey>
PAGE_KEY = <pagekey>
PROJECT = "eightway-io"

credentials = AnonymousCredentials()
client = Client(project=PROJECT, credentials=credentials)

docRef = client.collection("scoreboard").document(PACKAGE_KEY).collection(PAGE_KEY).document("fields")
document = docRef.get()
print(document.to_dict())
docRef.update({"fieldkey": "value"})

Hopefully this is helpful to future me-like people :)

Hi mflage,

is your project open source, i.e. do you have a project page somewhere (GitLab, GitHup, PyPi...)?

We are thinking of doing something similar...

Best.