Prerequisite: YouTube API
Google provides a large set of API’s for the developer to choose from. Each and every service provided by Google has an associated API. Being on of them, YouTube Data API is very simple to use provides features like –
- Search for videos
- Handle videos like retrieve information about a video, insert a video, delete a video etc.
- Handle Subscriptions like lists all the subscriptions, insert or delete a subscription etc.
In this article, we will discuss How to Extract YouTube Comments and reply using Google YouTube API in Python.
Understand step by step implementation:-
- Retrieve YouTube Video Results
- Here we will use commentThreads, list, execute method, it will give the list of comment and replies
- Inside list method, pass snippet and replies in part property and in videoId property pass video id of video URL
- Iterate through each Video Response and fetch comments and replies
- The data comes in dictionary format, each comment data has reply count number, if reply count number is zero means no reply on that comment
- if count is greater than zero then we are iterating each reply and get text.
- nextPageToken contain the next data, here we are checking if nextPageToken has no value it means value is None, loop end, else loop will continue.
Below is the full implementation:
Let’s verify the results:
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course