如何检索超过 25 条记录的 YouTube 用户的播放列表列表.YouTube API v2, C#.

本文关键字:YouTube 播放列表 用户 列表 API v2 记录 何检索 检索 | 更新日期: 2023-09-27 17:55:36

如何检索超过 25 条记录的 YouTube 用户播放列表列表。YouTube API v2, C#

我做了什么:

 Feed<Playlist> userPlaylists = request.GetPlaylistsFeed(youtubeUserID);  
                                 //i.e youtubeUserID = hollywoodlife09
 foreach (Playlist playlistInfo in userPlaylists.Entries) 
 {
    //work with playlist id.
    GetOtherVideosOfThisPlaylistId(playlistEntryUri.Segments[6]);
    //Segments[6] : it contain playlistId , i.e : "LL2rJLq19N0dGrxfib80M_fg"
 }

问题:它工作正常,但在这里我只能获得YouTube用户播放列表的25条记录..并且无法设置开始索引或使用Feed<播放列表>获取其他记录的内容>。

因此,任何人都知道如何获取其他记录。

如何检索超过 25 条记录的 YouTube 用户的播放列表列表.YouTube API v2, C#.

第一次获取所有 PlaylistID,然后,evryPlaylistID 再次使用 youtubeAPI 对其进行编译

      try
        {
            YouTubeRequestSettings settings = new YouTubeRequestSettings("YoutubeLibrary", DeveloperKey);
            settings.Timeout = 120000;
            int start = 1;
            int maxResult = 50;
            int totalVideosCroned = 0;
            var videosLimit=5; //how many max playlistID want ?? add here
            if (videosLimit < maxResult)
            {
                maxResult = videosLimit;
            }
            YouTubeRequest request = new YouTubeRequest(settings);
            do
            {
                totalVideosCroned += maxResult;
                string uri = "http://gdata.youtube.com/feeds/api/users/";
                if (!string.IsNullOrEmpty(youtubeID))
                {
                    uri += youtubeID  +"/playlists";
                    uri += "?key=" + DeveloperKey + "&start-index=" + start + "&max-results=" + maxResult;
                    //handle Playlist not found issue // use code for handling URL data 
                    string reponse = GetHttpResponseForPlayList(uri);

                        start += maxResult;
                        var videoEntryUrl = new Uri(uri);
                        Feed<Video> videoFeed = request.Get<Video>(videoEntryUrl);
                        foreach (Video entry in videoFeed.Entries)
                        {
                            string playlistId = Regex.Replace(entry.Id, ".*:playlist:", "");
                            //Do cron youtube with playlist ID now
                   CronPlaylistYoutubeVideo(playlistId);
                            totalVideosCroned = videosLimit;  // explicitly condition full feel to stop loop .
                        }
                        /*if (videoFeed.Entries.Count() < 50)  // if need to get more playlist records, : i.e if userAccount has 100 playlist then to get all, this should be uncomment
                        {
                            totalVideosCroned = videosLimit;
                        }*
                        /* This code will get 25 playlist records without use of gdata URI
                         * Feed<Playlist> userPlaylists = request.GetPlaylistsFeed(channelfilter.AccountName);
                        foreach (Playlist playlistInfo in userPlaylists.Entries)
                        {
                            Uri playlistEntryUri = new Uri(playlistInfo.Self);
                            CronPlaylistYoutubeVideo(playlistEntryUri.Segments[6], channelfilter, channel, videosLimit);
                            totalVideosCroned = videosLimit; // explicitly stop loop.
                        }*/

                }
                else
                {
                    totalVideosCroned = videosLimit;
                }
            } while (totalVideosCroned < videosLimit);
        }
        catch (Exception ex)
        {
           //handle it if need..
            return;
        }