与YouTube Api 2.0相关的视频限制
我正在使用.NET的YouTube数据API。
  我正在调用YouTubeRequest类的GetRelatedVideos功能,并返回与视频相关的25个视频,如下所示: 
Video video = Request.Retrieve<Video>(
    new Uri(String.Format("https://gdata.youtube.com/feeds/api/videos/{0}{1}",
        vID ,"?max-results=50&start-index=1")));  
Feed<Video> relatedVideos = Request.GetRelatedVideos(video);
return FillVideoInfo(relatedVideos.Entries);
请求链接如下:
https://gdata.youtube.com/feeds/api/videos/1FJHYqE0RDg?max-results=50&start-index=1
但是我得到这个错误
此资源不支持“最大结果”参数
如果我只是使用:
https://gdata.youtube.com/feeds/api/videos/1FJHYqE0RDg
然后我得到25个视频。 但我想获得50个视频和更多的页面。 我能够得到以下网址的结果:
https://gdata.youtube.com/feeds/api/videos/1FJHYqE0RDg/related?max-results=50&start-index=1
  在这里,我得到了一个回应,但是我只获得了25个视频,即使我通过了50个max-results参数。 
  我如何一次获得50个特定视频的相关视频,而不是默认的25(50是max-results的最大值)。 
  你不应该自己创建URL字符串,而应该使用YouTubeRequest类中的属性为你设置它们。 
  例如,获取时Video情况下,你不希望指定PageSize的财产YouTubeRequestSettings实例,就像这样: 
// Create the request.
var request = new YouTubeRequest(
    new YouTubeRequestSettings("my app", null) { AutoPaging = false });
// Get the video.
var video = request.Retrieve<Video>(
    new Uri("https://gdata.youtube.com/feeds/api/videos/1FJHYqE0RDg"));
  但是,您想在调用GetRelatedVideos方法时使用附加到YouTubeRequest实例的不同YouTubeRequestSettings : 
// Create the request again.  Set the page size.
request = new YouTubeRequest(
    new YouTubeRequestSettings("my app", null) { 
        AutoPaging = false, PageSize = 50
 });
 // Get the related videos.
 var related = request.GetRelatedVideos(video);
  现在它会返回50个视频。  如果您在获取视频时尝试设置PageSize属性,则会出现错误,因为获取单个视频时max-results参数无效。 
然后,您可以写出条目的数量来验证返回的50个条目:
// Write out how many videos there are.
Console.WriteLine(string.Format(CultureInfo.CurrentCulture, 
    "{0} related videos in first page.", related.Entries.Count()));
结果将是:
第一页中有50个相关视频。
链接地址: http://www.djcxy.com/p/28987.html上一篇: Limit of Related Videos with Youtube Api 2.0
下一篇: Which is the right Youtube Api URL to rate a video with an authenticated user?
