简体   繁体   English

Firebase 获取带有uid的用户头像

[英]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?我知道我可以获取当前登录用户的个人资料图片,但是如何根据他们的 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?是否有其他方法可以在 firebase auth 中获取另一个注册用户的个人资料图片 url? (I'm only using Javascript, no NodeJS, so I don't think I can use firebase admin?) (我只使用 Javascript,没有 NodeJS,所以我认为我不能使用 firebase 管理员?)

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.根本没有 API ,也没有低级别的权限。

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.如果您希望用户能够看到其他人的信息,您需要将该数据写入数据库,然后查询数据库以稍后获取它。

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

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