I am trying to use the Firebase Admin SDK to save values to a Firebase real-time database, but no matter what I do, none of the values are being saved. Unlike the tutorials, I am starting out with a completely empty database:
Firestore has a collection and document created, and if I switch to the real-time database from the Firestore view, the database also has this collection and document.
But if I press on the root link, the document and collection disappears. I am also constantly seeing "data" as null. Is data a document? A field? Is it just saying the database as a whole is empty? Sometimes it alternates between "data: null" and "coconut-xxx:null" which is odd.
I have also tried to reference /telemetry/data and write to it, but that didn't work. When I add a CompletionListener to setValue, the CompletionListener never seems to be called, so the connection is hanging or something?
My code:
String url = databaseUrl.getProtocol() + "://" + databaseUrl.getHost();
InputStream stream = getClass().getClassLoader().getResourceAsStream("firebaseCredentials.json");
GoogleCredentials credentials = GoogleCredentials.fromStream(stream);
FirebaseOptions options = new FirebaseOptions.Builder()
.setCredentials(credentials)
.setDatabaseUrl(url)
.build();
FirebaseApp.initializeApp(options);
DatabaseReference ref = FirebaseDatabase.getInstance().getReference();
ref.setValueAsync("12345");
I have also tried to send a Map like they do in the tutorial, but that doesn't work either.
I guess the only other thing that might be an issue is that I am doing this inside of an IntelliJ Android Studio plugin. That seems highly unlikely as a problem though..
Any help is appreciated. Thanks!
I found the problem. I don't know how this happened, but there was a mismatch between the service account JSON file in my IntelliJ resources folder, and the service account being used for the coconut project...
Anyway, the real-time database is working now!