Reputation: 5137
I'm trying to insert a new user record in to my Firebase database:
databaseReference
.child("users")
.child(firebaseUser.getUid())
.setValue(User.fromFirebaseUser(application.firebaseUser))
.addOnSuccessListener(new OnSuccessListener<Void>() {
@Override
public void onSuccess(Void aVoid) {
startActivity(MainActivity.createIntent(SplashActivity.this));
finish();
}
})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
showSnackbar(R.string.error_user_registration_failed);
}
})
.addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
Log.d(TAG, "complete");
}
});
But nothing happens. There is no messages from logcat and none of the listeners get hit.
My permissions are the default (must be authenticated) and I've made sure I am. A call to firebaseUser.getUid()
just before the database call returns the current userId as expected.
I've triple checked all my dependencies and made sure my google-services.json file is up to date.
I've tried to enable debugging via firebaseDatabase.setLogLevel()
but for some reason Logger.Level
doesn't contain the enums (they're obfuscated?)
Am I missing something?
Upvotes: 4
Views: 14853
Reputation: 63
Make sure you have "firebase_url": in google-services.json file in project_info": block. Some how in my case the URL option was not created.
Note: In the url option you have to give your firebase database link
Upvotes: 4
Reputation: 764
I had the same issue with reading the users data..
I changed the database rules to:
{
"rules": {
".read": true,
".write": true
}
}
And it worked, but make sure you kill the app first after changing and publishing the new rules.
Note: these rules are only for testing and should never be saved for the published app
Upvotes: 3
Reputation: 5137
After enabling debugging (thanks Bob Snyder) it gave me an error.
Essentially you need to enable the "Token Service API" in your Google Developer console. I'm not sure why and how this relates to FirebaseDatabase, and I couldn't find any references to it throughout Google's docs, but it worked.
Upvotes: 3