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

Fetching Comments using Youtube data API

$
0
0

Im trying to fetch all the comments for a particular Youtube video.I've written the following code:

#storing all the comments in a list (l)def video_comments(url):    # empty list for storing reply    replies = []    # creating youtube resource object    youtube = build('youtube', 'v3',                    developerKey=api_key)    # retrieve youtube video results    video_response=youtube.commentThreads().list(    part='snippet,replies',    videoId=url    ).execute()    for item in video_response['items']:        # Extracting comments        comment = item['snippet']['topLevelComment']['snippet']['textDisplay']        # counting number of reply of comment        replycount = item['snippet']['totalReplyCount']        # if reply is there        if replycount>0:            # iterate through all reply            for reply in item['replies']['comments']:                # Extract reply                reply = reply['snippet']['textDisplay']                # Store reply is list                replies.append(reply)        comment = remove_URL(comment)        # print comment with list of reply        l.append(comment)        for resp in replies:            resp = remove_URL(resp)            # print comment with list of replyprint(resp, replies, end = '\n\n')            l.append(comment)        # empty reply list        replies = []video_comments(n)

However, the following code fetches only 20-25 comments even though that video has hundreds-thousands of comments.


Viewing all articles
Browse latest Browse all 3831

Trending Articles