I’m using the YouTube Data API for .NET.
I am calling the GetRelatedVideos function on the YouTubeRequest class and it returns 25 videos that are related to a video, like so:
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);
Here is the request link:
https://gdata.youtube.com/feeds/api/videos/1FJHYqE0RDg?max-results=50&start-index=1
But I get this error
The ‘max-results’ parameter is not supported on this resource
If I just use:
https://gdata.youtube.com/feeds/api/videos/1FJHYqE0RDg
Then I get 25 videos. But I want to get 50 videos and and page for more. I am able to get a result for the following URL:
https://gdata.youtube.com/feeds/api/videos/1FJHYqE0RDg/related?max-results=50&start-index=1
Here I get a response, but but I only get 25 videos even though I passed 50 for the max-results parameters.
How can I get 50 related videos for a particular video at a time instead of the default 25 (50 is the max for max-results).
Instead of creating the URL string yourself, you should be using the properties on the
YouTubeRequestclass to set them for you.For example, when getting the
Videoinstance, you don’t want to specify thePageSizeproperty on theYouTubeRequestSettingsinstance, like so:However, you want to use a different
YouTubeRequestSettingsattached to theYouTubeRequestinstance when making the call toGetRelatedVideosmethod:Now it will return 50 videos. If you try and set the
PageSizeproperty when getting the video, you get an error because themax-resultsparameter is invalid when getting a single video.You can then write out the count of the entries to validate that 50 are returned:
The result will be: