ritesh
ritesh

Reputation: 229

Is there a limit on the number of comments to be extracted from Youtube?

I am trying to extract comments on some YouTubeVideos using the youtube-api with Java. Everything is going fine except the fact that I am not able to extract all the comments if the video has a large number of comments (it stops at somewhere in between 950 and 999). I am following a simple method of paging through the CommentFeed of the VideoEntry, getting comments on each page and then storing each comment in an ArrayList before writing them in an XML file. Here is my code for retrieving the comments

int commentCount = 0;
CommentFeed commentFeed = service.getFeed(new URL(commentUrl), CommentFeed.class);
do {
          //Gets each comment in the current feed and prints to the console
            for(CommentEntry comment : commentFeed.getEntries()) {
                    commentCount++;
                    System.out.println("Comment " + commentCount + " plain text content: " + comment.getPlainTextContent());
            }

           //Checks if there is a next page of comment feeds
            if (commentFeed.getNextLink() != null) {
                    commentFeed = service.getFeed(new URL(commentFeed.getNextLink().getHref()), CommentFeed.class);
            }
            else {
                commentFeed = null;
            }
        }
        while (commentFeed != null);

My question is: Is there some limit on the number of comments that I could extract or am I doing something wrong?

Upvotes: 4

Views: 939

Answers (2)

Safdar Abbas
Safdar Abbas

Reputation: 1

Google Search API and as well as Youtube Comments search limits max. 1000 results and u cant extract more than 1000 results

Upvotes: 0

TheWhiteRabbit
TheWhiteRabbit

Reputation: 15768

use/refer this

String commentUrl = videoEntry.getComments().getFeedLink().getHref();

CommentFeed commentFeed = service.getFeed(new URL(commentUrl), CommentFeed.class);
for(CommentEntry comment : commentFeed.getEntries()) {
  System.out.println(comment.getPlainTextContent());
}

source

Max number of results per iteration is 50 (it seems) as mentioned here

and you can use start-index to retrieve multiple result sets as mentioned here

Upvotes: 1

Related Questions