title: Get information from Firebase Realtime Database with Firebase Admin SDK
body: <p>I'm trying to get some information from Firebase Real-time database without success. I don't know what I'm doing wrong. I also tried the doc's example and they didn't work. Here's my code and my firebase db structue:</p>
  
  <p><img src="https://i.stack.imgur.com/fpN7y.png" alt="Database structure"></p>
  
  <p>Topics.java:</p>
  
  <pre><code>public class Topics {
  
   private String name;
  
   public Topics() {
  
   }
  
   public Topics(String name) {
      this.name = name;
   }
  
   public String getName() {
      return name;
   }
  
   public void setName(String name) {
      this.name = name;
   }
  
  }
  </code></pre>
  
  <p>Main.java</p>
  
  <pre><code>public static void main(String[] args) {
      // TODO Auto-generated method stub
      FileInputStream serviceAccount;
      FirebaseOptions options = null;
      try {
          serviceAccount = new FileInputStream(".//...");
          options = new FirebaseOptions.Builder()
                  .setCredentials(GoogleCredentials.fromStream(serviceAccount))
                  .setDatabaseUrl("...")
                  .build();
  
      } catch (FileNotFoundException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      } catch(IOException e) {
          e.printStackTrace();
      }
  
      FirebaseApp.initializeApp(options);
      String topics = getDatafromFirebase();
  
      System.out.println("Everything right!");
  }
  
  private static String getDatafromFirebase() {
      CountDownLatch done = new CountDownLatch(1);
      StringBuilder b = new StringBuilder();
      DatabaseReference dbRef = FirebaseDatabase.getInstance()
              .getReference();
  
      dbRef.child("topics").addValueEventListener(new ValueEventListener() {
          @Override
          public void onDataChange(DataSnapshot snapshot) {
              // TODO Auto-generated method stub
              if(snapshot.exists()) {
                  for(DataSnapshot s:snapshot.getChildren()) {
                      Topics t = s.getValue(Topics.class);
                      b.append(t.getName());
                      b.append(" ");
                      done.countDown();
                  }
              }
              else {
                  b.append("No existe ");
                  done.countDown();
              }
  
          }
  
          @Override
          public void onCancelled(DatabaseError error) {
              // TODO Auto-generated method stub
              b.append("Error: "+error.getDetails());
              done.countDown();
          }
          });
      try {
          done.await();
      } catch (InterruptedException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      }
      return b.toString();
  }
  </code></pre>
  
  <p>I have wait for the <code>CountDownLatch</code> for <code>5+</code> minutes, which I think is enough time for it to trigger. Also, important note: I have successfully sent message through firebase cloud messaging, so I don't think that it is a problem with the credentials.</p>