0

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?

omega
  • 40,311
  • 81
  • 251
  • 474
  • Is the pageToken getting used incorrectly? I haven't used this module for YT API so can't speak on that but have made similar mistakes with re-using pageToken/etc. You make an API request for this search and a pageToken is thrown for folllowing searches if they exist. – BGPHiJACK Apr 20 '22 at 18:00
  • I get the page token, and then I pass that token to the next call, but the next call gives me 1 result and an undefined next page token... Do I need to decode the page token or something before using it? – omega Apr 20 '22 at 18:12
  • OHHH okay, so that means you likely had a total of 101 comments. Can you confirm this? If no further pageToken you can assume search is over end of the list. The API is a bit tricky and will require you to check if the token come back undefined or defined to act accordingly. To trial try a 33 search and see – BGPHiJACK Apr 20 '22 at 18:14
  • Also I'd like to make note ordering by relevance may have an affect as it'd not list comments in order sometimes. – BGPHiJACK Apr 20 '22 at 18:17
  • No it definitely has more than 100 comments. The comments i get is like 100, 1, 100, 1, 100, etc... https://www.youtube.com/watch?v=dtfW6EP91fY – omega Apr 20 '22 at 18:21
  • I also tried it with ordering of time, and I get same results. – omega Apr 20 '22 at 18:21
  • Haven't used your module in question think what benjamin wrote will make more sense. – BGPHiJACK Apr 20 '22 at 18:33

1 Answers1

3

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.

Benjamin Loison
  • 3,782
  • 4
  • 16
  • 33