Youtube评论提取API V3

问题描述 投票:1回答:1

我正在使用此代码,但它不适用于API v2,请提供用于提取youtube注释的代码。

import gdata.youtube.service
yts = gdata.youtube.service.YouTubeService()
ytfeed = yts.GetYouTubeVideoCommentFeed(video_id="pXhcPJK5cMc")
comments = [comment.content.text for comment in ytfeed.entry]
python youtube
1个回答
0
投票

要使用YouTube API v.3提取YouTube视频评论,您需要一些Python代码,如下所示:

def get_video_comments(service, **kwargs):
    comments = []
    results = service.commentThreads().list(**kwargs).execute()

    while results:
        for item in results['items']:
            comment = item['snippet']['topLevelComment']['snippet']['textDisplay']
            comments.append(comment)

        # Check if another page exists
        if 'nextPageToken' in results:
            kwargs['pageToken'] = results['nextPageToken']
            results = service.commentThreads().list(**kwargs).execute()
        else:
            break

    return comments

有关此代码的详细信息以及如何使用YouTube API使用关键字搜索视频,然后将注释保存到CSV文件,您可以查看本教程:https://python.gotrained.com/youtube-api-extracting-comments/

© www.soinside.com 2019 - 2024. All rights reserved.