2017-09-25 3 views
1

코드를 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) 
          ) 
         ); 
        }); 
+0

데이터는 getComments 페치이다

프로필 PIC의 URL은 다음과 같이 comment.from.picture.data.url

그래서 코드는이다. 그래서 당신은 그 중 하나를 보여 주어야합니다. – WizKid

답변

0

그래서 답을 찾았습니다.

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) 
     ) 
    ); 
    });