Kimmax
Kimmax

Reputation: 1697

Get more then 25 comments from a Video

Question

I'm having promblems getting more then the default 25 comments per request in my application. I know I have to set the max-results parameter, but whenever I try to set it, the application crashes with a GDataRequestException with the information Execution of request failed. But the url looks okay:

http://gdata.youtube.com/feeds/api/videos/kpzWVicfdQk?max-results=50

Used code:

string url = String.Format("http://gdata.youtube.com/feeds/api/videos/{0}?max-results=50", "kpzWVicfdQk");

YouTubeRequest request = new YouTubeRequest(new YouTubeRequestSettings("GComments","***"));
Video v = request.Retrieve<Video>(new Uri(url));
Feed<Comment> comments = request.GetComments(v);

Without ?max-results=50 it works perfectly. I tried setting it to new Uri(url) too, but it does not work too.

Solution

The problem was, that the retrieved feed is a comment feed, but I used a kind of a video Feed. Here is the updated, now working, code:

void getComments()
{
    string url = String.Format("http://gdata.youtube.com/feeds/api/videos/{0}/comments?max-results={1}&start-index={2}", "kpzWVicfdQk", 50, 1);

    YouTubeRequest request = new YouTubeRequest(new YouTubeRequestSettings("GComments","AIzaSyB5d2gsN2G9xYftU3zFPKDg7kyBlrHni7A"));
    Feed<Comment> comments = request.Get<Comment>(new Uri(url));
}

Upvotes: 0

Views: 338

Answers (2)

Als
Als

Reputation: 1415

max-results can be 50. You have the wrong url for retrieving comments. Add "comments" after the videoId, like in:

 http://gdata.youtube.com/feeds/api/videos/kpzWVicfdQk/comments?v=2&max-results=50&start-index=1

Change start-index to advance if you expect more comments.

Or check the response for a rel="next" link, like:

<link rel='next' type='application/atom+xml' href='http://gdata.youtube.com/feeds/api/videos/kpzWVicfdQk/comments?start-index=51&amp;max-results=50&amp;direction=next&amp;v=2'/>

Upvotes: 1

Tom van Enckevort
Tom van Enckevort

Reputation: 4198

The max-results parameter only applies to feeds for finding multiple videos (i.e. if searching for videos by keyword, or most popular). It limits the number of returned videos. The parameter is not valid when retrieving a single video.

Upvotes: 1

Related Questions