【问题标题】:How to retrieve a list of the YouTube user's playlists more than 25 records. YouTube API v2, C#如何检索超过 25 条记录的 YouTube 用户播放列表列表。 YouTube API v2,C#
【发布时间】:2014-03-31 13:45:13
【问题描述】:

如何检索超过 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 条记录.. 并且无法设置 Start-index 或其他东西以使用 Feed .

所以,任何人都知道如何获取其他记录。

【问题讨论】:

    标签: c# youtube-api


    【解决方案1】:

    然后,首先获取所有 PlaylistID,evryPlaylistID 再次使用 youtubeAPI cron 它使用

          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;
            }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-12-11
      • 1970-01-01
      • 1970-01-01
      • 2012-01-17
      • 1970-01-01
      • 2014-04-25
      • 2012-03-20
      相关资源
      最近更新 更多