存储用户数据示例 - 显示名称不显示在数据库中 [英] Storing user data example - display name not showing in database

查看:89
本文介绍了存储用户数据示例 - 显示名称不显示在数据库中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有些困惑,为什么我的Firebase数据库中没有显示名称显示,我已经按照他们网站上的示例中的步骤,没有得到他们显示的预期结果。这里是示例代码。

 最终Firebase ref =新的Firebase(https://< YOUR-FIREBASE-APP> ;. firebaseio.com); 
ref.authWithPassword(jenny@example.com,correcthorsebatterystaple,
new Firebase.AuthResultHandler(){
@Override
public void onAuthenticated(AuthData authData){
//认证成功完成:)
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());

ref.child(users)。child(authData.getUid())。setValue(map);

@Override
public void onAuthenticationError(FirebaseError error){
//出错了:(
}
});

每当我尝试这个示例代码时,预期的结果与下面显示的类似。 / b>

  {
users:{
6d914336-d254-4fdb-8520-68b740e047e4:{
displayName:alanisawesome,
provider:password
},
002a448c-30c0-4b87-a16b-f70dfebe3386:{
displayName:gracehop,
provider:password
}
}
}

而不是显示类似于上面的内容,在我的数据库中只显示提供程序,而不是displayName。是否有必要的步骤来获取显示名称显示,或者应该在那里自动?



我试图看看这是什么包含在 authData.getProviderData(),这是我在打印出来的时候在控制台中产生的。

  01-25 17:58:51.921 15651-15651 /< package-name> I / System.out:{email=j.joe@hotmail.co.uk,isTemporaryPassword = false,profileImageURL = https://secure.gravatar.com/avatar/de53da9874178adb1a44b392ba5bed2f?d = retro} 


$ b因此,从结果产生它让我想知道是否以前从电子邮件中自动创建关键displayName和默认存储在 authData.getProviderData()这就是为什么它不再显示。

如果有人能解释哪里在数据库中的displayName来自于因为预期的结果来看,我似乎错过了一些东西。



谢谢!

解决方案

电子邮件+密码帐户没有一个关联的显示名称。它只需要一个电子邮件地址和一个密码。



您当然可以要求用户输入附加信息。不要把它传递给 createUser(),并且在调用 authWithPassword()之后不要覆盖它。 p>

更新:自Google I / O 2016发布Firebase身份验证更新以来,现在有一个显示名称属性为每个用户。因此,您还可以在Firebase身份验证本身中保留显示名称(尽管您无法查询/搜索)。


A bit confused why there's no display name being displayed in my Firebase database, I've followed the steps in the example on their website and didn't get the expected result which they showed. Here's the example code.

final Firebase ref = new Firebase("https://<YOUR-FIREBASE-APP>.firebaseio.com");
ref.authWithPassword("jenny@example.com", "correcthorsebatterystaple",
    new Firebase.AuthResultHandler() {
    @Override
    public void onAuthenticated(AuthData authData) {
        // Authentication just completed successfully :)
        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());
        }
        ref.child("users").child(authData.getUid()).setValue(map);
    }
    @Override
    public void onAuthenticationError(FirebaseError error) {
        // Something went wrong :(
    }
});

Whenever I tried this example code the expected result was to be something similar to what is shown below.

{
  "users": {
    "6d914336-d254-4fdb-8520-68b740e047e4": {
      "displayName": "alanisawesome",
      "provider": "password"
    },
    "002a448c-30c0-4b87-a16b-f70dfebe3386": {
      "displayName": "gracehop",
      "provider": "password"
    }
  }
}

Instead of showing something similar to the above, in my database only the provider is shown and not the displayName. Is there any necessary steps required to get the displayName to show or should it be there automatically?

I tried to look into this to see what was included within authData.getProviderData() and this was what was produced in the console when I printed it out.

01-25 17:58:51.921 15651-15651/<package-name> I/System.out: {email=j.joe@hotmail.co.uk, isTemporaryPassword=false, profileImageURL=https://secure.gravatar.com/avatar/de53da9874178adb1a44b392ba5bed2f?d=retro}

So from the result produced it's left me wondering if the key "displayName" was formerly automatically created from the email and stored by default in authData.getProviderData() and that's why it is no longer shown.

Would appreciate it if someone could explain where the displayName in the database comes from because judging by the expected result it seems I've missed something.

Thanks!

解决方案

An email+password account does not have an associated display name. It only requires an email address and a password.

You can definitely require the user to enter additional information. Just don't pass it to createUser() and don't overwrite it after calling authWithPassword().

Update: since the update to Firebase Authentication released at Google I/O 2016, there is now a display name property for each user. So you can also keep the display name in Firebase Authentication itself (although you won't be able to query/search for it).

这篇关于存储用户数据示例 - 显示名称不显示在数据库中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆