我是firebase的新手。我想在我的應用程序中使用firebase讀取/寫入數據,但是當我嘗試這樣做時,出現DatabaseError: Permission denied
錯誤。DatabaseError:權限被拒絕firebase
規則上的火力點
{
"rules": {
"sos":{
".read":"auth != null",
".write":"auth != null"
}
}
}
代碼文件文件
Firebase authFirebaseRef = new Firebase(ApiConstants.FIREBASE_MY_URL);
authFirebaseRef.authWithCustomToken(AppConstants.FBT, authResultHandler);
Firebase.AuthResultHandler authResultHandler = new Firebase.AuthResultHandler() {
@Override
public void onAuthenticated(AuthData authData) {
Log.v("onAuthenticated", authData.getUid());
addEvents();
}
@Override
public void onAuthenticationError(FirebaseError firebaseError) {
Log.v("onAuthenticationError= ", "FirebaseError= " + firebaseError.toString());
}
};
private void addEvents() {
mFirebaseDatabase = mFirebaseInstance.getReference("sos").child("emergencyservices");
mFirebaseDatabase.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
emergencyServicesList.clear();
for (DataSnapshot dataSnapshotChild : dataSnapshot.getChildren()) {
Log.v("onDataChange", ":" + dataSnapshotChild.child("emergencyServicesName").getValue());
EmergencyServiceModel emergencyServiceModel = new EmergencyServiceModel();
emergencyServiceModel.setEmergencyServiceId(dataSnapshotChild.child("emergencyServicesId").getValue().toString());
emergencyServiceModel.setEmergencyServiceName(dataSnapshotChild.child("emergencyServicesName").getValue().toString());
emergencyServicesList.add(emergencyServiceModel);
}
loadDataToRecyclerView();
}
@Override
public void onCancelled(DatabaseError databaseError) {
Log.v("DatabaseError", databaseError.getMessage());
}
});
}
早些時候,我在sos/emergencyservices
添加一些記錄通過保持.true
到read/write
。但現在我必須通過認證來改變它。
檢查此鏈接https://stackoverflow.com/questions/37424544/firebase-database-permission-denied-with-read-write-permissions-set-to-true –
你啓用從控制檯登錄? –
@akshay_shahane是的,我已經做過 – VVB