如何获取Facebook API评论者的个人资料照片?
问题描述:
我正在修改Facebook Live comments teleprompter的代码。如何获取Facebook API评论者的个人资料照片?
我希望能够显示个人资料图片以及个人评论的名称。目前,代码仅显示名称,取自comment.from.name
。
如何使用下面的代码使用Facebook Graph API获取评论者的个人资料照片?我试过comment.from.picture
,但这不起作用。
function refresh() {
$countdown.removeAttr('value');
lastReloadTime = null;
return getLastLiveVideo().then(function(video) {
// Merge video with comments and reactions
return $.when(
getComments(video.id),
getReactions(video.id)
).then(function(comments, reactions) {
video.comments = comments;
video.reactions = reactions;
return video;
});
}).then(function(video) {
$('.comments').empty();
video.comments.forEach(function(comment) {
$('.comments').append(
$('<div class="comment"></div>').append(
$('<h2 class="name">').text(comment.from.name),
$('<p class="time"></p>').text(
Math.floor(
(new Date() - new Date(comment.created_time))/1000/60
) + ' min. ago'
),
$('<p></p>').text(comment.message)
)
);
});
答
所以,我找到了答案。
轮廓PIC的网址是comment.from.picture.data.url
因此,代码如下:
function refresh() {
$countdown.removeAttr('value');
lastReloadTime = null;
return getLastLiveVideo().then(function (video) {
// Merge video with comments and reactions
return $.when(
getComments(video.id),
getReactions(video.id)
).then(function (comments, reactions) {
video.comments = comments;
video.reactions = reactions;
return video;
});
}).then(function (video) {
$('.comments').empty();
video.comments.forEach(function (comment) {
$('.comments').append(
$('<div class="comment"></div>').append(
$('<h2 class="name">').html("<img src=\""+comment.from.picture.data.url+"\" class=\"fbprofilepic\"/>"+comment.from.name),
$('<p class="time"></p>').text(
Math.floor(
(new Date() - new Date(comment.created_time))/1000/60
) + ' min. ago'
),
$('<p></p>').text(comment.message)
)
);
});
的数据是取在getComments。所以你必须展示一个 – WizKid