Youtube api v3 Get list of user's videos

来源:互联网 发布:js 获取qq音乐数据 编辑:程序博客网 时间:2024/05/17 08:29

I managed to retrieve all videos by user name using v2:

https://gdata.youtube.com/feeds/api/users/GoogleDevelopers/uploads?alt=json&start-index=1&max-results=50&v=2

I haven’t find an API to get all videos directly, however it can be done by two steps (thanks to http://stackoverflow.com/questions/22613903/youtube-api-v3-get-list-of-users-videos) :

Step 1: get the user’s relatedPlaylist (uploads) id by:

GET https://www.googleapis.com/youtube/v3/channels?part=contentDetails&forUsername=GoogleDevelopers&key={YOUR_API_KEY}

Step 2: get all videos by the id retrieved in step 1:

GET https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&playlistId=UU_x5XG1OV2P6uZZ5FSM9Ttw&key={YOUR_API_KEY}&maxResults=50

by javascript

// Get Uploads Playlist$.get(   "https://www.googleapis.com/youtube/v3/channels",{   part : 'contentDetails',    forUsername : 'USER_CHANNEL_NAME',   key: 'YOUR_API_KEY'},   function(data) {      $.each( data.items, function( i, item ) {          pid = item.contentDetails.relatedPlaylists.uploads;          getVids(pid);      });  });//Get Videosfunction getVids(pid){    $.get(        "https://www.googleapis.com/youtube/v3/playlistItems",{        part : 'snippet',         maxResults : 20,        playlistId : pid,        key: 'YOUR_API_KEY'},        function(data) {            var results;            $.each( data.items, function( i, item ) {                results = '<li>'+ item.snippet.title +'</li>';                $('#results').append(results);            });        }    );}<!--In your HTML --><ul id="results"></ul>
 

原创粉丝点击