【问题标题】:How can l retrieve users profile name information such as name and email and profile photo?如何检索用户个人资料名称信息,例如姓名和电子邮件以及个人资料照片?
【发布时间】:2019-09-10 11:45:22
【问题描述】:
private void firebaseAuthWithGoogle(GoogleSignInAccount acct) {
    Log.d(TAG, "firebaseAuthWithGoogle:" + acct.getId());

    AuthCredential credential = GoogleAuthProvider.getCredential(acct.getIdToken(), null);
    mAuth.signInWithCredential(credential)
            .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
                @Override
                public void onComplete(@NonNull Task<AuthResult> task) {
                    if (task.isSuccessful()) {

                        String currentUserID = mAuth.getCurrentUser().getUid();
                        DataRef.child("Users").child(currentUserID).child("Name").setValue(name);
                        DataRef.child("Users").child(currentUserID).child("Email").setValue(email);

                        // Sign in success, update UI with the signed-in user's information
                        Log.d(TAG, "signInWithCredential:success");
                        FirebaseUser user = mAuth.getCurrentUser();
                        updateUI();
                    } else {
                        // If sign in fails, display a message to the user.
                        Log.w(TAG, "signInWithCredential:failure", task.getException());
                        // Toast.makeText(MainActivity.this, task.getException().getLocalizedMessage(), Toast.LENGTH_SHORT).show();
                    }

                    // ...
                }
            });

用户信息类:

public class UserInformation {

    private String email;
    private String name;

    public UserInformation(){

    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}

【问题讨论】:

    标签: java android firebase firebase-realtime-database firebase-authentication


    【解决方案1】:

    首先分配 Firebase 用户。

    FirebaseUser firebaseUser = mAuth.getCurrentUser();
    

    将保存用户的数据。

    检索当前用户数据有不同的方法

    String userEmail = firebaseUser.getEmail();
    String uid = firebaseUser.getDisplayName();
    String photouri = String.ValueOf(firebaseUser.getPhotoUrl());
    

    【讨论】:

    • 您的用户登录成功还是抛出任何错误?
    【解决方案2】:

    task.isSuccessful(){你需要添加:

    user = FirebaseAuth.getInstance().getCurrentUser();
    if (user != null) {
        String uid = user.getUid();
        token = user.getUid();
        email = user.getEmail();
        displayName = user.getDisplayName();
    }
    

    【讨论】:

    • 成功了
    猜你喜欢
    • 2022-09-29
    • 2015-06-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多