Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
398 views
in Technique[技术] by (71.8m points)

YouTube API v3 - List uploaded videos

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...