Getting user name, lastname and ID in Firebase

。_饼干妹妹 提交于 2021-01-27 05:51:46

问题


I created a login/register using firebase, and it's working fine. But I need to get name and lastname from the user. How can I do this? And I'd like to know if it's possible to get an ID from the user, because I want to create a Rank Page in my app, so only an ID would be unique to do this.


回答1:


To get a Unique ID, you can use:

FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
String uid = user.getUid();

To get his name (I never tried this in Email/password auth, but it works fine on 3rd party providers auth):

String name = user.getDisplayName();



回答2:


For google sign-in you can use:

GoogleSignInAccount acct = GoogleSignIn.getLastSignedInAccount(getActivity());
if (acct != null) {
  String personName = acct.getDisplayName();
  String personGivenName = acct.getGivenName();
  String personFamilyName = acct.getFamilyName();
  String personEmail = acct.getEmail();
  String personId = acct.getId();
  Uri personPhoto = acct.getPhotoUrl();
}

link



来源:https://stackoverflow.com/questions/42056333/getting-user-name-lastname-and-id-in-firebase

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!