firebaseUser.getEmail()使用Firebase身份验证用户界面

时间:2019-03-17 07:53:41

标签: android firebase firebase-authentication

问题:

我面临一个问题。我在Android应用中使用Firebase Auth UI。我已要求在GoogleSignInOptions中发送电子邮件。

    GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
            .requestIdToken(getString(R.string.web_client_id))
            .requestEmail()
            .build();

在登录生成器中传递此GoogleSignInOptions

            new AuthUI.IdpConfig.GoogleBuilder()
                    .setSignInOptions(gso)
                    .build(),

现在,当我通过Google在应用中登录时,将调用onActivityResult(),那么我将无法通过FirebaseUser.getEmail()来获取电子邮件。 IdpResponse包含电子邮件。

IdpResponse response = IdpResponse.fromResultIntent(data); // response.getEmail() returns email

IdpResponse以上包含电子邮件。

FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser(); // user.getEmail() is null

FirebaseUser对象上方不包含电子邮件。

目的

我希望FirebaseUser对象中包含电子邮件。因为也有其他SignIn提供程序。像Facebook,电子邮件/密码,Twitter。所以我正在寻找独特的解决方案。

1 个答案:

答案 0 :(得分:0)

在此处Document link

检查文档
FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();

if (user != null) {
    for (UserInfo profile : user.getProviderData()) {
        // Id of the provider (ex: google.com)
        String providerId = profile.getProviderId();

        // UID specific to the provider
        String uid = profile.getUid();

        // Name, email address, and profile photo Url
        String name = profile.getDisplayName();
        String email = profile.getEmail();
        Uri photoUrl = profile.getPhotoUrl();
Toast.makeText(Activity.this, email, Toast.LENGTH_SHORT).show();
    }
}
相关问题