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

How to extract all YouTube comments using YouTube API? (Python)

$
0
0

Let's say I have a video_id having 8487 comments.
This code returns only 4309 comments.

def get_comments(youtube, video_id, comments=[], token=''):  video_response=youtube.commentThreads().list(part='snippet',                                               videoId=video_id,                                               pageToken=token).execute()  for item in video_response['items']:        comment = item['snippet']['topLevelComment']        text = comment['snippet']['textDisplay']        comments.append(text)  if "nextPageToken" in video_response:     return get_comments(youtube, video_id, comments, video_response['nextPageToken'])  else:    return commentsyoutube = build('youtube', 'v3',developerKey=api_key)comment_threads = get_comments(youtube,video_id)print(len(comment_threads))> 4309

How can I extract all the 8487 comments?


Viewing all articles
Browse latest Browse all 3718

Latest Images

Trending Articles



Latest Images

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