JIYONG
JIYONG

Reputation: 11

youtube api v3 return less results than entities

youtube api return fewer comments result than entities.

ex> the total of real comments : 103 comments

returned number of comments by youtube api : 86 comments
(sum of first page comments : 50, second page : 36)

I got the first page comments and I inputted 'nextpageToken' to get next page comments. but the api returned less than 50(requested maxResults). even thoungh the toal comments is 103 comments on the video.

is this a kind of bug?

I used youtube api.commentThreads().list

import os
import googleapiclient.discovery

def main():
     # Disable OAuthlib's HTTPS verification when running locally.
     # *DO NOT* leave this option enabled in production.
     os.environ["OAUTHLIB_INSECURE_TRANSPORT"] = "1"

     api_service_name = "youtube"
     api_version = "v3"
     DEVELOPER_KEY = "YOUR_API_KEY"
     youtube = googleapiclient.discovery.build(
     api_service_name, api_version, developerKey = DEVELOPER_KEY)

     request = youtube.commentThreads().list(
        part="snippet",
        maxResults=50,
        videoId="GazFsfcijXQ"
    )
    response = request.execute()

    print(response)

if __name__ == "__main__":
    main()
#######part of the first result
{
 "kind": "youtube#commentThreadListResponse",
 "etag": "\"Bdx4f4ps3xCOOo1WZ91nTLkRZ_c/lHjDTm_13OMmcHL6osO0eXmp450\"",
 "nextPageToken": "QURTSl9pMDRyOS1NcXNhbEwxeVlIVThfY1Q0RGFxaGFkNVRmREM3YmxOUGw4ZXpfUjd3Z1JxYWwxT19GQ180Nm1OMFdGbmJlX2lNV2hrODk4OGlMM0ZNTUVOeTUtbkFqbWU3Smd5aXhDRk9oc2t0SUpZdlJ3bGxOME1ldE5HUncxNmc=",
 "pageInfo": {
  "totalResults": 50,
  "resultsPerPage": 50
 },
#

and I use same code with nextpagetoken.

#
  nextpageToken="QURTSl9pMU5ISGYyUkpxWmRzSnBRejJjUXpRYVVNQ1RTZThrNnMzUUV0X1NyYUtXNmkyb1lxeXhqaVBSRnhqNGlCYXZ4bkNlNTVoZEtTVVNIcklURVlXWWkwSU9pZ2lBXy1ILUtNcDhsX2dub1ZPSGJuWkttYXRPaURvRXV4MGdBMWs="

def main():
    # Disable OAuthlib's HTTPS verification when running locally.
    # *DO NOT* leave this option enabled in production.
    os.environ["OAUTHLIB_INSECURE_TRANSPORT"] = "1"

    api_service_name = "youtube"
    api_version = "v3"
    DEVELOPER_KEY = "YOUR_API_KEY"
    youtube = googleapiclient.discovery.build(
        api_service_name, api_version, developerKey = DEVELOPER_KEY)

    request = youtube.commentThreads().list(
        part="snippet",
        maxResults=50, 
        pageToken = nextpageToken,
        videoId="GazFsfcijXQ",
    )
    response = request.execute()

    print(response)

if __name__ == "__main__":
    main()
######## the part of second result
    {
 "kind": "youtube#commentThreadListResponse",
 "etag": "\"Bdx4f4ps3xCOOo1WZ91nTLkRZ_c/LXcTjLwg3AUlu8RNlb7nbrei05A\"",
 "pageInfo": {
  "totalResults": 36,
  "resultsPerPage": 50
 },

I expect all comments of a video. the number of comments is less than 100~200 comments. so, I think I can get all comment regardless of the soft limit of youtube api.

Upvotes: 1

Views: 229

Answers (1)

stvar
stvar

Reputation: 6975

Please note to the fact that, for what concerns video comments, the API structures them in two categories and makes them accessible via two endpoints: CommentThreads and Comments.

As per the documentation (emphasis is mine):

The commentThread resource does not necessarily contain all replies to a comment, and you need to use the comments.list method if you want to retrieve all replies for a particular comment. Also note that some comments do not have replies.

Stated more explicitely, the replies.comments[] list does not contain all comments (again emphasis is mine):

A list of one or more replies to the top-level comment. Each item in the list is a comment resource.

The list contains a limited number of replies, and unless the number of items in the list equals the value of the snippet.totalReplyCount property, the list of replies is only a subset of the total number of replies available for the top-level comment.

Therefore, I deem the API is working OK. Any Youtube video page -- e.g. GazFsfcijXQ -- shows a comments counter that cumulates the number of top-level comments and the number of reply comments.

Upvotes: 1

Related Questions