Firebase会返回多个ID,这是唯一的ID? [英] Firebase returns multiple IDs, Which is unique one?

查看:122
本文介绍了Firebase会返回多个ID,这是唯一的ID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Firebase的新用户,并且正在尝试将Firebase身份验证API连接到我的应用程序中,我已经从

我已经成功登录了,在我的仪表板中,我登录了所有用户。

我的问题是我很迷惑从Firebase返回的各种ID



代码如下: / p>

  for(UserInfo profile:user.getProviderData()){
//提供者的ID(例如: com)
字符串providerId = profile.getProviderId();
//如果提供者的id是firebase,这意味着我们在保存到firebbase后成功获取数据,因此我们继续应用
(providerId.equals(firebase)){
// UID特定于提供者
Other.SavePref(this,LoginToken,profile.getUid());

//名称,电子邮件地址和个人资料照片Url
String name = profile.getDisplayName();
String email = profile.getEmail();
Uri photoUrl = profile.getPhotoUrl();
$ b $ Log.e(userinfo,::+ profile.getUid()+::+ name +::+ email +::+ photoUrl);
}
};

在上面的代码中,我只检查providerId是否是firebase,然后我存储信息,但如果我不不要这么做,它会向我提供两次来自Firebase的数据


  1. 来自Google的

我有两个userIds,如果我使用这个方法: profile.getUid()了解哪一个是独一无二的?我应该用哪个?



在应用程序端获得成功登录后,这将是非常有用的。

解决方案

用户可以登录多个提供程序。每个提供商为该用户生成自己的唯一ID。您可以通过用户访问这些内容每个供应商的信息

除此之外,Firebase身份验证还会为用户生成自己的唯一ID。无论用户使用哪个提供者,他们最终都会得到相同的UID。您可以在

要标识用户,通常使用 FirebaseUser.getUid(),所以在你的代码片段中: user.getUid()


I am new to Firebase and i am trying to connect Firebase Auth api into my application, I have followed documentation from newer updated documentation from Official site and all things work fine.

I have done successful SignIn and in my dashboard i got all users after they login.

My problem is i am so confuse about various IDs returned from Firebase

Code is as follows :

 for (UserInfo profile : user.getProviderData()) {
                // Id of the provider (ex: google.com)
                String providerId = profile.getProviderId();
                //if Id of the provider is firebase it means we have successfully get back data after saving in firebbase hence we continue to app
                if(providerId.equals("firebase")) {
                    // UID specific to the provider
                    Other.SavePref(this, "LoginToken", profile.getUid());

                    // Name, email address, and profile photo Url
                    String name = profile.getDisplayName();
                    String email = profile.getEmail();
                    Uri photoUrl = profile.getPhotoUrl();

                    Log.e("userinfo", "  ::  " + profile.getUid()+ " :: " + name + " :: " + email + " :: " + photoUrl);
                }
            };

as in above code i am only checking if providerId is firebase then i store information, but if i don't do it, it will give me data two times

  1. from Firebase
  2. from Google also

and i got two userIds if i use this method : profile.getUid(), I just want to know which one is unique? and which i should use?

And someone can proposed a way for what to do after getting successful signin at application side, It would be very helpful..

解决方案

A user can sign in with multiple providers. Each provider generates its own unique ID for that user. You can access these under the user info for each provider.

On top of that Firebase Authentication also generates its own unique ID for the user. No matter which provider the user signed in with, they'll end up with the same UID for that. You can find this under FirebaseUser.getUid().

To identify a user, you'd normally use the value from FirebaseUser.getUid(), so in your snippet: user.getUid().

这篇关于Firebase会返回多个ID,这是唯一的ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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