Youtube 数据 API:获得总评论、喜欢、不喜欢

Youtube Data API: getting total comments, likes, dislikes

我有这个问题。

我有一个 YouTube 频道列表,我正在从 API 进行轮询以每天获取一些统计数据。

我已经实现了下面的方法,它有效,但它一次循环播放每个视频,点击 API。

有没有办法用多个视频 ID 进行一次 API 调用?

或者是否有更好的方法来执行此操作并获取这些统计信息?

#find stats for all channel videos - how will this scale?
def video_stats(row):
  videoid = row['video_id']
  query = yt.get_video_metadata(videoid)
  vids = pd.DataFrame(query, index=[0])
  df['views'] = vids['video_view_count'].sum()
  df['comments']  = vids['video_comment_count'].sum()
  df['likes'] = vids['video_like_count'].sum()
  df['dislikes'] = vids['video_dislike_count'].sum()
  return 'no'

df['stats'] = df.apply(video_stats, axis = 1)

channel['views'] = df['views'].sum()
channel['comments'] = df['comments'].sum()
channel['likes'] = df['likes'].sum()
channel['dislikes'] = df['dislikes'].sum()

根据docs, you may cumulate in one Videos.listAPI端点调用几个不同视频的ID:

id: string

The id parameter specifies a comma-separated list of the YouTube video ID(s) for the resource(s) that are being retrieved. In a video resource, the id property specifies the video's ID.

但是,您显示的代码过于简洁,无法找到一种方法使其适应此类(批量)端点调用。