从视频中获取超过 25 条评论

本文关键字:评论 视频 获取 | 更新日期: 2023-09-27 18:31:17

问题

我的应用程序中每个请求获得的 promblems 比默认的 25 条评论更多。我知道我必须设置 max-results 参数,但是每当我尝试设置它时,应用程序都会崩溃并显示带有信息Execution of request failed GDataRequestException。但是网址看起来不错:

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

使用的代码:

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

没有?max-results=50它就能完美地工作。我也尝试将其设置为new Uri(url),但它也不起作用。

溶液

问题是,检索到的提要是评论提要,但我使用了一种视频提要。以下是更新的、正在工作的代码:

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

从视频中获取超过 25 条评论

最大结果可以是 50。您有错误的 URL 来检索评论。在 videoId 后添加"评论",如下所示:

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

如果需要更多评论,请更改开始索引以前进。

或者检查 rel="next" 链接的响应,例如:

<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'/>

max-results 参数仅适用于用于查找多个视频的 Feed(即,如果按关键字或最受欢迎的关键字搜索视频)。它限制了返回的视频数量。检索单个视频时,该参数无效。