YouTube的API V3 - 列表上传的视频(YouTube API v3 - List up

2019-06-18 13:08发布

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

Answer 1:

第一步是越来越该用户的信道ID。 我们可以请求做这个Channels的服务。 这里有一个例子JS。

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服务。

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.
});


Answer 2:

如果你正在使用的客户端,然后格雷格的答案是正确的。 要做到与您进行以下2个请求基本要求同样的事情:

  1. GET https://www.googleapis.com/youtube/v3/channels

    与参数:

     part=contentDetails mine=true key={YOUR_API_KEY} 

    和标题:

     Authorization: Bearer {Your access token} 

    从此你会得到像这样的JSON响应:

     { "kind": "youtube#channelListResponse", "etag": "\"some-string\"", "pageInfo": { "totalResults": 1, "resultsPerPage": 1 }, "items": [ { "id": "some-id", "kind": "youtube#channel", "etag": "\"another-string\"", "contentDetails": { "relatedPlaylists": { "likes": "channel-id-for-your-likes", "favorites": "channel-id-for-your-favorites", "uploads": "channel-id-for-your-uploads", "watchHistory": "channel-id-for-your-watch-history", "watchLater": "channel-id-for-your-watch-later" } } } ] } 

    从这个要分析出来的“上传”通道ID。

  2. GET https://www.googleapis.com/youtube/v3/playlistItems

    与参数:

     part=snippet maxResults=50 playlistId={YOUR_UPLOAD_PLAYLIST_ID} key={YOUR_API_KEY} 

    和头文件:

     Authorization: Bearer {YOUR_TOKEN} 

    从此,您将收到类似以下的JSON响应:

     { "kind": "youtube#playlistItemListResponse", "etag": "\"some-string\"", "pageInfo": { "totalResults": 1, "resultsPerPage": 50 }, "items": [ { "id": "some-id", "kind": "youtube#playlistItem", "etag": "\"another-string\"", "snippet": { "publishedAt": "some-date", "channelId": "the-channel-id", "title": "video-title", "thumbnails": { "default": { "url": "thumbnail-address" }, "medium": { "url": "thumbnail-address" }, "high": { "url": "thumbnail-address" } }, "playlistId": "upload-playlist-id", "position": 0, "resourceId": { "kind": "youtube#video", "videoId": "the-videos-id" } } } ] } 

使用这种方法,你应该能够得到使用任何语言,甚至只是卷曲的信息。 如果你想比前50个结果更多,那么你将不得不做使用第二个请求多个查询,并通过在页面请求。 :更多关于这可以在读取http://developers.google.com/youtube/v3/docs/playlistItems/list



文章来源: YouTube API v3 - List uploaded videos