I am trying to retrieve data from a Firebase Realtime database using the Firebase Admin SDK in java (in a java server context). The authentication is done using the service account. I followed all the steps in the official documentation. In the following snippet, the callback onDataChange is supposed to be called at least one time to give access to the initial snapshot.
Every instruction is silently done, so it suggests everything is right (authentication, connection to the database), but this callback is never called.
Do you have any idea of what is going wrong?
final CountDownLatch latch = new CountDownLatch(1);
GoogleCredentials credentials = GoogleCredentials.fromStream(serviceAccount);
FirebaseOptions options = FirebaseOptions.builder()
.setCredentials(credentials)
.setDatabaseUrl( getDBUrl() )
.setDatabaseAuthVariableOverride(auth)
.build();
FirebaseApp app = FirebaseApp.initializeApp(options);
DatabaseReference dbRef = FirebaseDatabase.getInstance().getReference( ref );
dbRef.addValueEventListener(new ValueEventListener() {
public void onDataChange(DataSnapshot ds) {
System.out.println("onDataChange");
latch.countDown();
}
public void onCancelled(DatabaseError de) {
System.out.println("onCancelled");
latch.countDown();
}
});
latch.await();
edit
link right under it.