Firebase admin SDK Java

144 views
Skip to first unread message

Noman Arain

unread,
Feb 4, 2017, 11:40:22 AM2/4/17
to Firebase Google Group
I'm trying to setup my admin sdk. `FirebaseOptions options = new FirebaseOptions.Builder()

               .setCredential(FirebaseCredentials.applicationDefault())

               .setDatabaseUrl("https://mkastrive.firebaseio.com")

               .build();

       // Initialize the default app

       FirebaseApp defaultApp = FirebaseApp.initializeApp(options);

Map<String, User> users = new HashMap<String, User>();

       users.put("alanisawesome", new User("June 23, 1912", "Alan Turing"));

       users.put("gracehop", new User("December 9, 1906", "Grace Hopper"));

       defaultDatabase.child("users").push().setValue(users);`

But the setValue doesn't work :

Kato Richardson

unread,
Feb 6, 2017, 2:50:06 PM2/6/17
to Firebase Google Group
Noman,

What's the error? Have you added some callbacks into your setValue() call to see?

☼, Kato


--
You received this message because you are subscribed to the Google Groups "Firebase Google Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-talk+unsubscribe@googlegroups.com.
To post to this group, send email to fireba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/8724608e-364d-4294-9ea0-925ab42acd95%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--

Kato Richardson | Developer Programs Eng | kato...@google.com | 775-235-8398

Jacob Wenger

unread,
Feb 6, 2017, 6:02:22 PM2/6/17
to fireba...@googlegroups.com
Hey Norman,

There is probably a permission issue going on. As Kato suggested, you can attach an error handler to your setValue() call and see if it gets called:

defaultDatabase.child("users").push().setValue(users, new DatabaseReference.CompletionListener() {
    @Override
    public void onComplete(DatabaseError databaseError, DatabaseReference databaseReference) {
        if (databaseError != null) {
            System.out.println("Data could not be saved " + databaseError.getMessage());
        } else {
            System.out.println("Data saved successfully.");
        }
    }
});

You also can turn on debug logging for the Database API by putting this line of code right after your initialization code (and before you read or write any data):

FirebaseDatabase.getInstance().setLogLevel(Logger.Level.DEBUG);

If I had to bet what is going wrong, your call to get the Application Default Credential is not working properly. Maybe you are running the code in an environment where the default project does not correspond to the database URL you are providing. Or maybe you are not properly signed in to get the Application Default Credential. Without some error information, I can't say for sure though.

Cheers,
Jacob

Reply all
Reply to author
Forward
0 new messages