为什么不能看到这个用户的用户名? [英] Why cant I see the username of this user?
问题描述
我正在使用Firebase进行用户身份验证,通过电子邮件和密码,我想从 authData
中检索用户名,但我只看到流体
。我想检索用户名,以便我可以在另一个活动上显示它。
这是我的代码:
button.setOnClickListener(new View .OnClickListener(){
@Override
public void onClick(View v){
ref.authWithPassword(email.getText()。toString(),password.getText()。toString() ,new Firebase.AuthResultHandler(){
@Override
public void onAuthenticated(AuthData authData){
setContentView(R.layout.activity_user_display);
Map< String,String> map = new HashMap< String,String>();
map.put(provider,authData.getProvider());
if(authData.getProviderData()。containsKey(displayName)){
map.put(displayName,authData.getProviderData().get(displayName)。toString());
}
else
{
上下文c = getApplicationContex吨();
吐司t = Toast.makeText(c,你以为你有它,Toast.LENGTH_SHORT);
ref.child(users)。child(authData.getUid())。setValue(map);
$ b @Override
public void onAuthenticationError(firebaseError firebaseError){
Context c = getApplicationContext();
Toast错误= Toast.makeText(c,Sorry :),Toast.LENGTH_SHORT);
}
});
}
});`
结果是这个结果上面的代码:
可能您应该创建一个单独的数据库来存储客户端的用户名。由于uid存储了特定客户端的所有信息,所以你可能需要一个单独的数据库。
这可以帮助你:
希望它对你有所帮助。
I am using Firebase for user authentication through email and password and I want to retrieve the username of a user from authData
but I only see the uid
. I want to retrieve the username so I can display it on another activity.
Here is my code:
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ref.authWithPassword(email.getText().toString(), password.getText().toString(), new Firebase.AuthResultHandler() {
@Override
public void onAuthenticated(AuthData authData) {
setContentView(R.layout.activity_user_display);
Map<String, String> map = new HashMap<String, String>();
map.put("provider", authData.getProvider());
if(authData.getProviderData().containsKey("displayName")){
map.put("displayName", authData.getProviderData().get("displayName").toString());
}
else
{
Context c = getApplicationContext();
Toast t = Toast.makeText(c, "You thought you had it", Toast.LENGTH_SHORT);
}
ref.child("users").child(authData.getUid()).setValue(map);
}
@Override
public void onAuthenticationError(FirebaseError firebaseError) {
Context c = getApplicationContext();
Toast error = Toast.makeText(c,"Sorry :)",Toast.LENGTH_SHORT);
}
});
}
});`
and the result is this the result from the code above:
Thank you.
Probably, you should create a separate DB to store Username of the clients. Since the uid stores all the info of that specific client, u probably need a separate DB.
This might help you :
About Authentication using email
Similar Question for retrieving email in FireBase
Hope it helped you.
这篇关于为什么不能看到这个用户的用户名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!