【问题标题】:Firebase returns multiple IDs, Which is unique one?Firebase 返回多个 ID,哪个是唯一的?
【发布时间】:2017-01-02 16:26:09
【问题描述】:

我是 Firebase 的新手,我正在尝试将 Firebase Auth api 连接到我的应用程序中,我遵循了来自 Official site 的更新文档中的文档,并且一切正常。

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

我的问题是我对从 Firebase 返回的各种 ID 感到非常困惑

代码如下:

 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);
                }
            };

在上面的代码中,我只检查 providerId 是否为 firebase,然后我存储信息,但如果我不这样做,它会给我两次数据

  1. 来自 Firebase
  2. 也来自 Google

如果我使用这种方法,我会得到两个 userId:profile.getUid(),我只想知道 哪个是唯一的?我是哪个应该用吗?

并且有人可以提出一种在应用程序端成功登录后要做什么的方法,这将非常有帮助..

【问题讨论】:

  • 对不起,当你说“如果我使用此方法,我有两个 userId:profile.getUid()”时,我没有得到,用于一次调用方法或对同一方法进行不同调用?
  • 假设我使用方法 profile.getUid() 而不检查提供者是 firebase 的条件,那么它将返回 firebase 和 google @MKJParekh 的 id

标签: android firebase firebase-authentication


【解决方案1】:

用户可以使用多个提供商登录。每个提供商都会为该用户生成自己的唯一 ID。您可以在每个提供商的user info 下访问这些。

除此之外,Firebase 身份验证还会为用户生成自己的唯一 ID。无论用户使用哪个提供商登录,他们最终都会获得相同的 UID。您可以在FirebaseUser.getUid() 下找到它。

要识别用户,您通常会使用来自FirebaseUser.getUid() 的值,因此在您的 sn-p 中:user.getUid()

【讨论】:

  • 好的,但是 user.getUid() 返回什么?从火力基地或谷歌方面有什么价值吗?
  • 它返回一个唯一标识用户的不透明值。这是唯一的保证。
  • @FrankvanPuffelen 它在不同的应用程序中是否是独一无二的。我有两个具有相同后端服务器的不同应用程序。
  • @FrankvanPuffelen 文档中某处是否有可能提供者 ID 的列表?看看是否有任何帮助将非常有帮助。 (我知道 providerId 可以是“facebook.com”、“password”,但我想知道所有可能的值)。
  • @FrankvanPuffelen 是的,我也想知道这份名单。
猜你喜欢
  • 2018-03-05
  • 1970-01-01
  • 2017-10-01
  • 2015-01-30
  • 2014-01-04
  • 2011-09-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多