检索当前用户的数据(user_id)Firebase? [英] Retrieve Current User's Data (user_id) Firebase?
本文介绍了检索当前用户的数据(user_id)Firebase?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
firebaseAuth = FirebaseAuth.getInstance();
mDatabase = FirebaseDatabase.getInstance();
mDb = mDatabase.getReference();
FirebaseUser user = firebaseAuth.getCurrentUser();
userKey = user.getUid();
mDb.child(userKey).addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
Log.d(TAG, "Name: " + dataSnapshot.child("user_id").getValue());
userID = String.valueOf(dataSnapshot.child("user_id").getValue());
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
我不知道我的代码有什么问题,我想检索用户ID的值.
I do not know what is wrong with my code, I want to retrieve value of user id.
推荐答案
要解决此问题,请使用以下代码:
To solve this, please use the following code:
firebaseAuth = FirebaseAuth.getInstance();
mDatabase = FirebaseDatabase.getInstance();
mDb = mDatabase.getReference();
FirebaseUser user = firebaseAuth.getCurrentUser();
userKey = user.getUid();
mDb.child("Tunanetra").child(userKey).addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
String userID = dataSnapshot.child("user_id").getValue(String.class);
Log.d(TAG, "Name: " + userID);
}
@Override
public void onCancelled(DatabaseError databaseError) {}
});
使用此代码,您将能够在logcat中打印出经过身份验证并存在于Tunanetra
节点下的用户的id
.如果用户位于Orangtua
节点下,则只需将Tunanetra
更改为Orangtua
.
With this code, you'll be able to print out in the logcat, the id
of the users that is authenticated and exists under Tunanetra
node. If the user exists under the Orangtua
node, then just change Tunanetra
with Orangtua
.
这篇关于检索当前用户的数据(user_id)Firebase?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文