YouTube API v3 - 列出上传的视频

问题描述:

如何在 V3 api 中列出用户上传的视频?

How do I list the user's uploaded videos in the V3 api?

第一步是获取该用户的频道 ID.我们可以通过对 Channels 服务的请求来做到这一点.这是一个 JS 示例.

The first step is getting the channel id for that user. We can do this with request to the Channels service. Here's a JS example.

var request = gapi.client.youtube.channels.list({
  // mine: true indicates that we want to retrieve the channel for the authenticated user.
  mine: true,
  part: 'contentDetails'
});
request.execute(function(response) {
  playlistId = response.result.channels[0].contentDetails.uploads;
});

一旦我们获得播放列表 ID,我们就可以使用它来查询来自 PlaylistItems 服务的上传视频列表.

Once we get the playlist id we can use that to query for the list of uploaded videos from the PlaylistItems service.

var request = gapi.client.youtube.playlistItems.list({
  playlistId: playlistId,
  part: 'snippet',
});
request.execute(function(response) {
  // Go through response.result.playlistItems to view list of uploaded videos.
});