YouTube API v3 - List uploaded videos

后端 未结 2 697
死守一世寂寞
死守一世寂寞 2020-11-30 00:47

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

2条回答
  •  难免孤独
    2020-11-30 01:17

    If you are using the client then Greg's answer is correct. To do the same thing with basic requests you make the following 2 requests:

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

      with parameters:

      part=contentDetails
      mine=true
      key={YOUR_API_KEY}
      

      and header:

      Authorization:  Bearer {Your access token}
      

      From this you will get a JSON response like so:

      {
       "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"
          }
         }
        }
       ]
      }
      

      From this you want to parse out the "uploads" channel-id.

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

      with parameters:

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

      and headers:

      Authorization:  Bearer {YOUR_TOKEN}
      

      From this you will receive a JSON response like the following:

      {
       "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"
          }
         }
        }
       ]
      }
      

    With this method you should be able to get the info using any language or even just curl. If you want more than the first 50 results, then you will have to do multiple queries using the second request and pass in page requests. More on this can be read at: http://developers.google.com/youtube/v3/docs/playlistItems/list

提交回复
热议问题