Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8319443
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T22:19:46+00:00 2026-06-08T22:19:46+00:00

I’m using the YouTube API to get comments for a video with a parameterized

  • 0

I’m using the YouTube API to get comments for a video with a parameterized query like the following:

http://gdata.youtube.com/feeds/api/videos/theVideoID/comments?v=2&alt=json

The problem with this is that the maximum number of results you can get per query is 50. I want to get every comment. I’m currently using the start-index and max-results parameters to solve this. I had a bit of trouble doing iterations of 50 at a time because sometimes the iteration would have a start-index above the number of comments and I couldn’t figure that out, so I just tried to work out one at a time. It may be better to do 50 at a time, so let me know if that is the better solution. For now:

I’m using PHP to get the amount of comments:

<?php
    $video_ID = 'gT2HYxOdxUk';
    $JSON = file_get_contents("https://gdata.youtube.com/feeds/api/videos/{$video_ID}?v=2&alt=json");
    $JSON_Data = json_decode($JSON);
    $commentCount = $JSON_Data->{'entry'}->{'gd$comments'}->{'gd$feedLink'}->{'countHint'};
?>

And then I’m calling a JavaScript/jQuery function to load all comments into an array. For testing, it prints them into a div. For starters, here’s how I’m calling the function:

<body onLoad="loadComments('<?php echo $commentCount; ?>', '<?php echo $video_ID; ?>')">

Next, the actual function:

function loadComments(count, videoID) {     
    for(i = 1; i <= count; i++) {
        $.ajax({
            url: "http://gdata.youtube.com/feeds/api/videos/" + videoID + "/comments?v=2&alt=json&max-results=1" + "&start-index=" + i,
            dataType: "jsonp",
            success: function(data){
                $.each(data.feed.entry, function(key, val) {
                    comments.push(val.content.$t);
                    $('#commentOutput').append(val.content.$t + '<br>'); //Just for testing purposes.
                });
            }

        });
    }
}

The problem is that it is really iffy. When I use the count variable as the terminating part of the for loop like this, it always gets like, for example, 45 out of 211 comments. If I manually enter 211, it will go to around 195. If I put in a low number, like 1-15, it pretty much always gets them all. 20+, it’s never right.

I need to figure out how to get this to consistently get all the comments of a given video by taking advantage of the max-results and start-index parameters. Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T22:19:50+00:00Added an answer on June 8, 2026 at 10:19 pm

    I just came across this question and I notice that its been quite some time when this was asked. But since nobody answered it yet, I think I should do that.

    What you should ideally do is, use Youtube’s PHP API (using Zend_GData) and use the following code in PHP:

    <?php
    
        require_once 'Zend/Loader.php'; // the Zend dir must be in your include_path
    Zend_Loader::loadClass('Zend_Gdata_YouTube');
    
    $yt = new Zend_Gdata_YouTube();
    $yt->setMajorProtocolVersion(2);
    $video = parse_url("http://www.youtube.com/watch?v=K-ob8sr9ZX0");
    parse_str(urldecode($video['query']), $query);
    $videoId = $query['v'];
    
    $commentFeed = $yt->retrieveAllEntriesForFeed($yt->getVideoCommentFeed($videoId));
    
    foreach ($commentFeed as $commentEntry) {
        echo "Full text: " . $commentEntry->content->text . "<br />";
    }
    

    The key element here is the retrieveAllEntriesForFeed() method.

    Instead of echo-ing all the comments, you can construct a JSON and send it back to the waiting Javascript.

    It does not use the max-results or start-index, but does the job well without them.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm making a simple page using Google Maps API 3. My first. One marker
I would like my Web page http://www.gmarks.org/math_in_e-mail.txt on my Apache 2.2.14 server to display
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.