Quantcast
Channel: Active questions tagged youtube-api - Stack Overflow
Viewing all articles
Browse latest Browse all 3831

list() returns different number of comments from a video

$
0
0

I'm trying to crawl comments of a given videoId with youtube API.But the number of crawled comments is less than its actual number.Do you have any idea about this? My code is like the below.

from googleapiclient.discovery import buildfrom typing import Listdef get_comments(api, video_id: str, fields: str)-> List[List[str]]:    comments = list()    response = api.commentThreads().list(part='snippet', fields=fields, videoId=video_id, maxResults=50).execute()    all_comment_crawled = True    while all_comment_crawled:        for item in response['items']:            comment = item['snippet']['topLevelComment']['snippet']            comments.append([comment['textOriginal'], comment['likeCount']])        if 'nextPageToken' in response:            response = api.commentThreads().list(part='snippet', videoId=video_id, fields=fields, pageToken=response['nextPageToken'], maxResults=50).execute()        else:            all_comment_crawled = False    return commentsapi_key = "MY_API_KEY"api_obj = build('youtube', 'v3', developerKey=api_key)video_id = 'fgSvGLxanCo'fields = 'items(snippet(totalReplyCount, topLevelComment(snippet(textOriginal, likeCount)))), nextPageToken'comments = get_comments(api_obj, video_id, fields)print(len(comments)) # returns 1,945 actually is over 2,000

Viewing all articles
Browse latest Browse all 3831

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>