我正在修改Facebook Live comments teleprompter。
中的代码我希望能够显示个人资料图片以及评论人员的姓名。目前,代码仅显示名称,取自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)
)
);
});
答案 0 :(得分:0)
所以,我找到了答案。
个人资料照片的网址位于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)
)
);
});