英文:
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().
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论