简体   繁体   English

如何通过具有电子邮件登录功能的FirebaseAuth获取登录Android应用的电子邮件帐户用户的照片url

[英]how to get photo url of email account user signed into android app through FirebaseAuth with Email signIn

I used Firebase Authentication with only Email/Password in an android app project. 我在Android应用程序项目中仅对电子邮件/密码使用了Firebase身份验证。 I tried to access the picture of the email account which has been used to log into the app. 我试图访问已用于登录应用程序的电子邮件帐户的图片。 However, the photoUrl is null when I try these three methods below and I am testing with my own email account which I know has a profile picture. 但是,当我尝试以下三种方法时,photoUrl为空,并且正在使用自己的电子邮件帐户进行测试,我知道该帐户具有个人资料图片。

    // METHOD ONE
    Uri photoUrl = mFirebaseUser.getPhotoUrl();

    if (photoUrl != null) {
        log.d("PhotoUrl",photoUrl.toString());
    }


    // METHOD TWO
    UserInfo userInfo = mFirebaseUser.getProviderData().get(0);
    Uri photoUrl = (Uri) userInfo.getPhotoUrl();

    if (photoUrl != null) {
        log.d("PhotoUrl",photoUrl.toString());
    }


    // METHOD THREE
    for (UserInfo userInfo:mUser.getProviderData()) {

        Uri photoUrl = userInfo1.getPhotoUrl();

        if (photoUrl != null){
            break;
        }
    }

    if (photoUrl != null) {
        log.d("PhotoUrl",photoUrl.toString());
    }

I am able to get the name of the email account easily like this 我可以像这样轻松获得电子邮件帐户的名称

    String name = mFirebaseUser.getDisplayName();

Try This 尝试这个

  private FirebaseAuth mAuth;
  private FirebaseUser mCurrentUser;

Initialize it 初始化

mAuth = FirebaseAuth.getInstance();
mCurrentUser = mAuth.getCurrentUser();

Load the Photo Url Using Picasso in Your ImageView 在您的ImageView中使用Picasso加载照片网址

 Picasso.get().load(mCurrentUser.getPhotoUrl())
                .into(imageView);

As you are using Email sign in only in FirebaseAuth, so the problem happens when you try to retrieve the photo url of the user because there is no photo url for the user by default. 由于仅在FirebaseAuth中使用电子邮件登录,因此当您尝试检索用户的照片url时会发生问题,因为默认情况下该用户没有照片url。 So what you can do is you can ask user to set the photo and save the url with the FirebaseAuth (so that you can retrieve later). 因此,您可以要求用户设置照片并使用FirebaseAuth保存网址(以便以后可以检索)。 You can use the code below to save the photo url for the user. 您可以使用以下代码为用户保存照片网址。

UserProfileChangeRequest userProfileChangeRequest = new UserProfileChangeRequest.Builder() .setDisplayName("set new display name") .setPhotoUri(uri) .build(); FirebaseAuth.getInstance().getCurrentUser().updateProfile(userProfileChangeRequest);

after setting the photo url. 设置照片网址后。 Try getting the photo url 尝试获取照片网址

FirebaseAuth.getInstance().getCurrentUser().getPhotoUrl();

Hope this helps! 希望这可以帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 FirebaseAuth-复制修改的用户登录名/电子邮件 - FirebaseAuth - Replication of a modifed user login/email 如何使用oauth2服务帐号获取登录用户的电子邮件? - How to get the email of the logged user with oauth2 service account? 如何从 Android 设备(如 Google Pay 应用程序)获取用户名和电子邮件地址 - How to get user name and email address from android device like Google Pay app 使用Java通过同一用户帐户访问多个电子邮件箱 - Access Multiple Email Boxes through Same user Account using Java 当用户使用其Facebook帐户登录时,如何获取用户的姓名,电子邮件和个人资料图片? - How do I get the user's name, email, and profile picture when the user logs in with their Facebook account? 如何获取 Android 用户的电子邮件地址? - How can you get an Android user's email address? 如何确定用户是否已在Firebase中使用电子邮件进行了注册? - How to determine if the user has signed up using email in Firebase? 从Android中的特定电子邮件帐户触发电子邮件 - Triggering email from a specific email account in android 如何动态登录pop3电子邮件? - how dynamically signin to a pop3 email is possible? 如何在不使用 email 或 firebase android 中的电话号码的情况下制作自定义用户帐户 - How to make a custom user account without using email or phone number in firebase android
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM