Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

117
Views
How to get the total number of comment of a channel using YouTube Data API

I am using YouTube Data API and can get subscriber count, view count etc. by using the statistics parameter. I am aware that statistics cannot be used to get total likeCount and commentCount for a channel. But the API allows to get the playlist videos using contentDetails.relatedPlaylists.uploads.

So, my question is

How can I use the contentDetails.relatedPlaylists.uploads to fetch individual videos' likes and comments and append them into a JS variable?

EDIT

The embedded videos with titles are showing perfectly. But commentCount for the video does not show up. Here is the code

function requestVideoPlaylist(playlistId) {
  const requestOptions = {
    playlistId: playlistId,
    part: 'snippet,contentDetails,statistics',
    maxResults: 10
  };

  const request = gapi.client.youtube.playlistItems.list(requestOptions);

  request.execute(response => {
    console.log(response);
    const playListItems = response.result.items;
    if (playListItems) {
      let output = '<br><h4 class="center-align">Latest Videos</h4>';

      // Loop through videos and append output
      playListItems.forEach(item => {
          const videoId = item.snippet.resourceId.videoId;
          const videoTitle = item.snippet.title;
          const videoComment = item.statistics.commentCount;

        output += `
          <div class="col s3">
          <iframe width="100%" height="auto" src="https://www.youtube.com/embed/${videoId}" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe>
"${videoTitle}" "${videoComment}"
          </div>
        `;
      });

      // Output videos
      videoContainer.innerHTML = output;
    } else {
      videoContainer.innerHTML = 'No Uploaded Videos';
    }
  });
}

Help will be greatly appreciated.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

For getting the commentNumber from the statistics part of Videos: list in plain JavaScript (because what you seem to do with the library seems correct but not working):

var getJSON = function(url, callback) {
    var xhr = new XMLHttpRequest();
    xhr.open('GET', url, true);
    xhr.responseType = 'json';
    xhr.onload = function() {
      var status = xhr.status;
      if (status === 200) {
        callback(null, xhr.response);
      } else {
        callback(status, xhr.response);
      }
    };
    xhr.send();
};

getJSON('https://www.googleapis.com/youtube/v3/videos?part=statistics&id=VIDEO_ID&key=API_KEY',
function(err, data) {
  if (err !== null) {
    alert('Something went wrong: ' + err);
  } else {
    alert('The video commentCount: ' + data.items[0].statistics.commentCount);
  }
});
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!