我将“user_id”作为输入并传递给我的Js函数,该函数假设给我个人资料照片数据。我正在尝试显示该照片。登录用户个人资料图片显示正常。但是当我传递注销的user_id时,得到错误并且它显示“TypeError:response.picture is undefined”。这是第一次,我试图使用fb api只通过user_id获取用户信息。这是我的功能。“a”来自我的输入。
// without login,just giving username and getting profile picture
function getInfopeople(a) {
//https://graph.facebook.com/user_id/picture /me/picture?redirect=false&height=300' //this part is not working
var user_id = "/"+a + "/picture";
console.log(user_id);
FB.api('/http://graph.facebook.com/user_id,','GET', {fields:'picture.width(150).height(150)'}, function(response) {
document.getElementById('user_status').innerHTML = "<img src='" + response.picture.data.url + "'>";
});
}
您正在进行不正确的API调用。您应该调用此API来获取用户个人资料图片。
function getInfopeople(user_id) {
// https://graph.facebook.com/{version}/{user_id}?fields=picture.width(150).height(150)
FB.api('/' + user_id, 'GET', { fields:'picture.width(150).height(150)' }, function(response) {
document.getElementById('user_status').innerHTML = "<img src='" + response.picture.data.url + "'>";
});
}