通过Firebase在Android应用中进行身份验证:获取用户的名字和姓氏。

huangapple go评论83阅读模式
英文:

Auth in the Android app via Firebase: Get the user’s first and last name

问题

有两行可以解释这种情况:

FirebaseAuth mAuth = FirebaseAuth.getInstance(); //现在用户已经通过Google账号登录
String name = mAuth.getCurrentUser().getDisplayName();//"Walter White";

我们如何分开用户的名字和姓氏?人们的名字和姓氏可能由几个单词组成,所以我们不能仅通过空格来分隔:" "。

英文:

There are two rows that can explain the situation:

FirebaseAuth mAuth = FirebaseAuth.getInstance(); //Now user already loggined via Google account
String name = mAuth.getCurrentUser().getDisplayName();//"Walter White"

How can we separate the user's name and surname? People can have a couple of words on his name and surname, this way we can't just separate it by space: " ".

答案1

得分: 2

FirebaseUser类中没有可以返回名字和姓氏的方法,这两者都是在单个方法调用的结果中返回的。然而,你可以创建一个方法来将整个名字分成两个或更多个单独的名字,但这并没有太大的帮助,因为你不知道哪一个是名字,哪一个是姓氏。

一个解决方法是使用Google进行Firebase身份验证,在那里你会找到一个有趣的类叫做GoogleSignInAccount,其中你可以找到诸如getFamilyName()getGivenName()的方法。

英文:

There is no method in FirebaseUser class that can return the first name and the last name, both are returned as a result of a single method call. However, you can create a method to split the entire name in two or more separate names but is not much of a help because you don't know which one is the first name and which one is the last name.

A workaround would be to implement Firebase authentication with Google, where you'll find an interesting class named GoogleSignInAccount, in which you can find methods like getFamilyName() and getGivenName().

huangapple
  • 本文由 发表于 2020年4月10日 21:25:15
  • 转载请务必保留本文链接:https://go.coder-hub.com/61141251.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定