答案 0 :(得分:1)
我假设您要从任何可能的follower
中删除followed user
的UID:
如果这是您想要的,那么您必须阅读Follow
节点,并删除follower UID
的所有可能存在的地方:
//the user ID
String userID = FirebaseAuth.getInstance().getCurrentUser().getUid();
//the main reference node "Follow"
DatabaseReference mDatabase = FirebaseDatabase.getInstance().getReference().child("Follow");
//read the node and loop through all UIDs
ValueEventListener listener = new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
//loop through all UIDs under "Follow" and remove the user ID that deleted his/here account from "followers"
for(DataSnapshot ds : dataSnapshot.getChildren()){
if(ds.child("followers").child(userID).exists()){
ds.child("followers").child(userID).getRef().removeValue();
}
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
Log.w(TAG, "loadPost:onCancelled", databaseError.toException());
}
};
mDatabase.addValueEventListener(listener);
答案 1 :(得分:1)
如果用户删除帐户,则应从整个Firebase数据结构中删除其UID,以便您可以执行以下操作: 如果要删除其帐户的用户已登录,请执行以下操作: 您可以指定一个名为 Delete Account 的按钮,并在该按钮的onclicklistener上实现以下代码。
FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
DatabaseReference followRef = FirebaseDatabase.getInstance().getReference().child("Follow").child(user.getUid()).child("following");
followRef.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
for (DataSnapshot data : dataSnapshot.getChildren()) {
//Getting User id from dataSnapshot
String userid = data.getValue(String.class);
DatabaseReference Ref = FirebaseDatabase.getInstance().getReference().child("Follow").child(userid).child("followers").child(user.getUid());
Ref.removeValue();
}
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
Log.i(TAG, "onCancelled: Error: " + databaseError.getMessage());
}
});
DatabaseReference followRef1 = FirebaseDatabase.getInstance().getReference().child("Follow").child(user.getUid());
followRef1.removeValue();
DatabaseReference followRef2 = FirebaseDatabase.getInstance().getReference().child("Users").child(user.getUid());
followRef2.removeValue();
如果有任何疑问,请告诉我 谢谢。
答案 2 :(得分:0)
要删除密钥,请尝试以下操作:
FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
DatabaseReference followRef = FirebaseDatabase.getInstance().getReference().child("Follow");
followRef.child(user.getUid()).removeValue();
获取当前登录的用户,然后调用removeValue()
删除该节点。