使用Firebase返回链接到用户帐户的图像
问题描述:
我目前正在使用android studio制作应用程序,并且目前拥有使用Firebase用户身份验证的工作登录名。但是,我试图在用户使用此身份验证后进行日志时在屏幕上显示图像。我希望将该图像链接到该特定用户。这可能吗?像这样使用Firebase返回链接到用户帐户的图像
FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
UserProfileChangeRequest profileUpdates = new UserProfileChangeRequest.Builder()
.setDisplayName("Jane Q. User")
.setPhotoUri(Uri.parse("https://example.com/jane-q-user/profile.jpg"))
.build();
user.updateProfile(profileUpdates)
.addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
if (task.isSuccessful()) {
Log.d(TAG, "User profile updated.");
}
}
});
你会然后获取用户的个人信息(包括他们的照片网址):
答
您可以用下面的代码在用户的火力配置文件中设置照片网址
FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
if (user != null) {
// Name, email address, and profile photo Url
String name = user.getDisplayName();
String email = user.getEmail();
Uri photoUrl = user.getPhotoUrl();
// Check if user's email is verified
boolean emailVerified = user.isEmailVerified();
// The user's ID, unique to the Firebase project. Do NOT use this value to
// authenticate with your backend server, if you have one. Use
// FirebaseUser.getToken() instead.
String uid = user.getUid();
}
更多信息:https://firebase.google.com/docs/auth/android/manage-users
如果您使用oAuth身份验证并希望从Facebook检索他们的个人资料照片,您会发现更多信息abou t如何做到这一点在下面的链接:
https://firebase.google.com/docs/auth/android/facebook-login