我按照教程使用AuthUI.IdpConfig库来使用Firebase身份验证 -
FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
if (user != null) {
Log.d(TAG, "Logged in");
} else {
Log.d(TAG, "Not logged in");
// Choose authentication providers
List<AuthUI.IdpConfig> providers = Arrays.asList(
new AuthUI.IdpConfig.Builder(AuthUI.EMAIL_PROVIDER).build(),
new AuthUI.IdpConfig.Builder(AuthUI.FACEBOOK_PROVIDER).build());
// Create and launch sign-in intent
startActivityForResult(
AuthUI.getInstance()
.createSignInIntentBuilder()
.setAvailableProviders(providers)
.build(),
RC_SIGN_IN);
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == RC_SIGN_IN) {
IdpResponse response = IdpResponse.fromResultIntent(data);
if (resultCode == RESULT_OK) {
// Successfully signed in
Log.d(TAG, "Successful sign in");
FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
Log.d(TAG, "The token is " + FirebaseInstanceId.getInstance().getToken());
// ...
} else {
Log.d(TAG, "Unsuccessful sign in");
// Sign in failed, check response for error code
// ...
}
}
}
我的问题是以下代码不会更新我的firebase数据库...
FirebaseDatabase database = FirebaseDatabase.getInstance();
DatabaseReference myRef = database.getReference("message");
myRef.setValue("Hello, World!");
除非我先使用
退出FirebaseAuth.getInstance().signOut();
我的规则设置为'true',用于读取和写入数据库。为什么登录会影响写入数据库?
答案 0 :(得分:0)
你需要在setValue();
之前使用.child()或push()//List data
myRef.push().setValue()
//Simple data
myRef.child("key").setValue()