从频道获取所有YouTube视频(仅显示25个视频)asp.net

时间:2015-03-03 07:18:20

标签: asp.net video youtube

我必须从youtube频道获取所有视频。我使用了以下代码,但它只返回前25个视频。我需要所有上传的视频。请帮我解决这个问题。

 public class YoutubeVideoHelper
{
    const string YOUTUBE_CHANNEL = "UPGovtOfficial";
    const string YOUTUBE_DEVELOPER_KEY = "My Developer key";

   public static DataTable GetVideos()
   {
       DataTable dt = new DataTable();
       dt.Columns.Add("Title");
       dt.Columns.Add("VideoId");
       YouTubeRequestSettings settings =
       new YouTubeRequestSettings(YOUTUBE_CHANNEL, YOUTUBE_DEVELOPER_KEY);
       YouTubeRequest request = new YouTubeRequest(settings);
       string feedUrl = String.Format
       ("http://gdata.youtube.com/feeds/api/users/{0}/uploads?orderby=published&max-result=100", 
    YOUTUBE_CHANNEL);
       Feed<Video> videoFeed = request.Get<Video>(new Uri(feedUrl));

       foreach (var video in videoFeed.Entries)
       {
           DataRow dr = dt.NewRow();
           dr["Title"] = video.Title;
           dr["VideoId"] = video.VideoId;
           dt.Rows.Add(dr);
       }

       return dt;

   }
}

1 个答案:

答案 0 :(得分:0)

试试这个:

AutoPaging设置为true,并将MaximumPageSize属性值指定为YouTubeRequestSettings对象的所需值(100)。

以下是更多详细信息的链接:

http://google-gdata.googlecode.com/svn-history/r890/docs/folder54/AllMembers_T_Google_GData_Client_RequestSettings.htm