问题
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