private void GetComments_OnClick(object sender, RoutedEventArgs e) { var videoReq = youtubeService.Videos.List("statistics"); videoReq.Id = VideoId.Text; var videoRes = videoReq.Execute(); MessageBox.Show(String.Format("{0} comments", videoRes.Items[0].Statistics.CommentCount)); var list = new List <Comment>(); string nextPageToken = ""; while (nextPageToken != null) { CommentThreadsResource.ListRequest req = youtubeService.CommentThreads.List("snippet"); req.MaxResults = 100; req.Fields = "items(snippet(topLevelComment(snippet(textDisplay,authorDisplayName,authorProfileImageUrl)))),nextPageToken"; req.VideoId = VideoId.Text; req.TextFormat = CommentThreadsResource.ListRequest.TextFormatEnum.PlainText; req.PageToken = nextPageToken; CommentThreadListResponse res = req.Execute(); if (res.Items != null) { foreach (CommentThread re in res.Items) { var data = new Comment { Content = re.Snippet.TopLevelComment.Snippet.TextDisplay, AuthorDisplayName = re.Snippet.TopLevelComment.Snippet.AuthorDisplayName, AvatarUrl = re.Snippet.TopLevelComment.Snippet.AuthorProfileImageUrl }; list.Add(data); } } nextPageToken = String.IsNullOrWhiteSpace(res.NextPageToken) ? null : res.NextPageToken; } MessageBox.Show("pobrane: " + list.Count.ToString()); list = list.Where(a => a.Content.Contains("27")).ToList(); Comments.ItemsSource = list; MessageBox.Show("z liczbą: " + list.Count.ToString()); var t = list.GroupBy(a => a.Content); foreach (var k in t) { if (k.Count() > 1) { //MessageBox.Show(String.Format("{0}: {1}", k.FirstOrDefault().AuthorDisplayName, k.Key)); } } }
public static CommentThreadListResponse GetCommentThreadListResponse(string videoId, int maxComments) { // Initialize the youtube service with the API key YouTubeService youtubeService = GetYoutubeService(); // Construct the request CommentThreadsResource.ListRequest commentThreadsListRequest = youtubeService.CommentThreads.List("snippet"); commentThreadsListRequest.MaxResults = maxComments; commentThreadsListRequest.TextFormat = CommentThreadsResource.ListRequest.TextFormatEnum.PlainText; commentThreadsListRequest.VideoId = videoId; // Retrieve the response CommentThreadListResponse commentThreadsListResponse = commentThreadsListRequest.Execute(); // Return the response return(commentThreadsListResponse); }