YouTube API v3 - 列出上传的视频

efi*_*ic1 33 youtube-api youtube-data-api

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

Cha*_*fus 41

如果您正在使用客户端,那么Greg的答案是正确的.要对基本请求执行相同的操作,请执行以下2个请求:

  1. 获取https://www.googleapis.com/youtube/v3/channels

    带参数:

    part=contentDetails
    mine=true
    key={YOUR_API_KEY}
    
    Run Code Online (Sandbox Code Playgroud)

    和标题:

    Authorization:  Bearer {Your access token}
    
    Run Code Online (Sandbox Code Playgroud)

    从这里你将得到一个像这样的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"
        }
       }
      }
     ]
    }
    
    Run Code Online (Sandbox Code Playgroud)

    从这里你想要解析"上传"频道ID.

  2. 获取https://www.googleapis.com/youtube/v3/playlistItems

    带参数:

    part=snippet
    maxResults=50
    playlistId={YOUR_UPLOAD_PLAYLIST_ID}
    key={YOUR_API_KEY}
    
    Run Code Online (Sandbox Code Playgroud)

    和标题:

    Authorization:  Bearer {YOUR_TOKEN}
    
    Run Code Online (Sandbox Code Playgroud)

    从这里你将收到如下的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"
        }
       }
      }
     ]
    }
    
    Run Code Online (Sandbox Code Playgroud)

使用这种方法,您应该能够使用任何语言获取信息,甚至只是卷曲.如果您想要超过前50个结果,那么您将不得不使用第二个请求进行多个查询并传入页面请求.有关详细信息,请参阅:http://developers.google.com/youtube/v3/docs/playlistItems/list


Gre*_*ter 32

第一步是获取该用户的频道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;
});
Run Code Online (Sandbox Code Playgroud)

获得播放列表ID后,我们可以使用该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.
});
Run Code Online (Sandbox Code Playgroud)