omega
omega

Reputation: 43893

Getting inconsistent YouTube API v3 results when using pagination

I'm using the youtube data api v3 in node.js and I am getting inconsistent result set lengths when getting comment threads from a video.

https://developers.google.com/youtube/v3/docs/commentThreads/list

When I query a video with id "dtfW6EP91fY" using code

        var service = google.youtube('v3');
        service.commentThreads.list({
            auth: auth,
            part: "id,snippet,replies",
            videoId: "dtfW6EP91fY",
            order: "relevance",
            maxResults: 100,
            pageToken
        }, (err, response) => {

        });

(on each response, I save the next token and set it back for the next call)

But I get strange result sets. I first see 100 comments, and then I see 1 comment, and then I see 100 comments, and then 1, and it keeps alternating.

Not only that but for the responses that get 1 result, the next page token comes out undefined as well.

How can I get consistent 100 comments?

Upvotes: 0

Views: 366

Answers (1)

Benjamin Loison
Benjamin Loison

Reputation: 5642

According to YouTube your video dtfW6EP91fY has 308 comments. However you are only able to retrieve 101 comments through CommentThreads: list and that's normal.

The replies when using CommentThreads: list are given up to 5 replies. If the message have more than 5 replies you have to use Comments: list to list them all. That's why you are missing a lot of comments.

Upvotes: 3

Related Questions