0
現在、アンドロイドスタジオを使用しているアプリケーションで作業しており、現在Firebaseユーザー認証を使用してログインしています。しかし、この認証を使用した後にユーザーがログオンすると、画面に画像が表示されるようにしようとしています。この画像をその特定のユーザーにリンクさせたいと思います。これは可能ですか?Firebaseを使用すると、ユーザーアカウントにリンクされた画像が返されます
現在、アンドロイドスタジオを使用しているアプリケーションで作業しており、現在Firebaseユーザー認証を使用してログインしています。しかし、この認証を使用した後にユーザーがログオンすると、画面に画像が表示されるようにしようとしています。この画像をその特定のユーザーにリンクさせたいと思います。これは可能ですか?Firebaseを使用すると、ユーザーアカウントにリンクされた画像が返されます
次のコードで、ユーザーのfirebaseプロフィールに写真のURLを設定することができます。
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.");
}
}
});
あなたがそのようにように(自分の写真のURLを含む)は、ユーザのプロファイル情報を取得することができます。
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から取得したい場合は、詳細についてはこちらをご覧ください。次のリンクでそれを行う方法:
https://firebase.google.com/docs/auth/android/facebook-login