gpt4 book ai didi

android - Firebase 返回多个 ID,哪个是唯一的?

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:45:22 25 4
gpt4 key购买 nike

我是 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

如果我使用此方法,我会得到两个用户 ID:profile.getUid(),我只想知道哪个是唯一的?我哪个应该怎么用?

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

最佳答案

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

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

要识别用户,您通常会使用 FirebaseUser.getUid() 中的值,因此在您的代码段中:user.getUid()

关于android - Firebase 返回多个 ID,哪个是唯一的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39158816/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com