简体   繁体   中英

Firebase get user profile picture with uid

I know I can get the current logged in user's profile picture, but how do I get someone else's based on their uid? Here's what I tried:

database.ref("classes/" + currentClassId + "/chat/main").on('value', (snapshot) => {
    var p = 0
    console.log(snapshot.val())
    if(snapshot.val() != null){p = snapshot.val().data.msgCount}
    var min = p - 100
    if(min <= 0){min = 0}
    var max = p
    $("#log").empty()
    if(snapshot.val() != null){
        for(i=min; i<=max - 1; i++){
            console.log(i)
            database.ref("classes/" + currentClassId + "/chat/main/log/" + i).once('value').then(s => {
                $("#log").append([
                    $("<div/>").append([ 
                        $("<img/>").attr("src", firebase.auth().getUser(s.val().sender.uid).then(function(profile){
                            return profile.PhotoUrl // <<<<<< !!!!!! This part doesnt work !!!!!! <<<<<<
                        })),
                        $("<p/>").text(s.val().message).addClass("message")
                    ]).css("display: inline;")
                ])
            })
        }
    }
})

Here's what I got:

Uncaught (in promise) TypeError: firebase.auth(...).getUser is not a function
    at <anonymous>:178:65

Is there another way to get the profile picture url of another registered user in firebase auth? (I'm only using Javascript, no NodeJS, so I don't think I can use firebase admin?)

What you're trying to do isn't possible from client app code. For security reasons, users can not directly access other users' profile information at all. There is simply no API for it, and no permission at a low level.

If you want users to be able to see information about others, you will need to write that data to a database, then query the database to get a hold of it later.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM