private async void UpdateComments(CommentThreadsResource.ListRequest.OrderEnum option) { //Clear the current comments commentCollection.Clear(); var methods = new YoutubeMethods(); //Get the comments var service = YoutubeMethodsStatic.GetServiceNoAuth(); var getComments = service.CommentThreads.List("snippet,replies"); getComments.VideoId = Constants.activeVideoID; getComments.Order = option; getComments.TextFormat = CommentThreadsResource.ListRequest.TextFormatEnum.PlainText; getComments.MaxResults = 10; var response = await getComments.ExecuteAsync(); //Save the next page token commentNextPageToken = response.NextPageToken; //Add them to our collection so that they will be updated on the UI foreach (var commentThread in response.Items) { commentCollection.Add(new CommentContainerDataType(methods.CommentToDataType(commentThread))); } }
private async void ViewMoreButton_Click(Windows.UI.Xaml.Documents.Hyperlink sender, Windows.UI.Xaml.Documents.HyperlinkClickEventArgs args) { if (!isExpanded) { isExpanded = !isExpanded; //ViewMoreButton. var methods = new YoutubeMethods(); var service = YoutubeMethodsStatic.GetServiceNoAuth(); var getReplies = service.Comments.List("snippet"); getReplies.ParentId = Source.Id; getReplies.TextFormat = Google.Apis.YouTube.v3.CommentsResource.ListRequest.TextFormatEnum.PlainText; var response = await getReplies.ExecuteAsync(); commentReplies.Clear(); foreach (var item in response.Items) { var comment = methods.CommentToDataType(item); //If there are no likes, set it to null if (comment.LikeCount == 0) { comment.LikeCount = null; } commentReplies.Add(comment); } } else { isExpanded = !isExpanded; commentReplies.Clear(); foreach (var item in Source.Replies) { if (commentReplies.Count > 2) { break; } //If there are no likes, set it to null if (item.LikeCount == 0) { item.LikeCount = null; } commentReplies.Add(item); } } }
private async void ReplyBoxSend_Click(Windows.UI.Xaml.Documents.Hyperlink sender, Windows.UI.Xaml.Documents.HyperlinkClickEventArgs args) { if (ReplyBox.Text == null || ReplyBox.Text == "") { ReplyContainer.Visibility = Visibility.Collapsed; return; } try { var service = await YoutubeMethodsStatic.GetServiceAsync(); Comment comment = new Comment(); comment.Snippet = new CommentSnippet(); comment.Snippet.TextOriginal = ReplyBox.Text; comment.Snippet.ParentId = Source.Id; var returnedComment = await service.Comments.Insert(comment, "snippet").ExecuteAsync(); //Add the comment to the UI var methods = new YoutubeMethods(); commentReplies.Add(methods.CommentToDataType(returnedComment)); //Hide the reply box ReplyContainer.Visibility = Visibility.Collapsed; } catch (Google.GoogleApiException ex) { if (ex.Error.Code == 403) { Constants.MainPageRef.ShowNotifcation("You have not setup a channel with your account. Please do so to post a comment.", 0); } else if (ex.Error.Code == 400) { Constants.MainPageRef.ShowNotifcation("Your comment was too long or Youtube failed to handle the request correctly.", 5000); } else { Constants.MainPageRef.ShowNotifcation("An error occured."); } } }
private async void AddComments(CommentThreadsResource.ListRequest.OrderEnum option) { if (isAdding) { return; } isAdding = true; //Check if there are more comments if (commentNextPageToken == null || commentNextPageToken == "") { return; } var methods = new YoutubeMethods(); //Get the comments var service = YoutubeMethodsStatic.GetServiceNoAuth(); var getComments = service.CommentThreads.List("snippet,replies"); getComments.VideoId = Constants.activeVideoID; getComments.Order = option; getComments.TextFormat = CommentThreadsResource.ListRequest.TextFormatEnum.PlainText; getComments.PageToken = commentNextPageToken; getComments.MaxResults = 15; var response = await getComments.ExecuteAsync(); //Save the next page token commentNextPageToken = response.NextPageToken; //Add them to our collection so that they will be updated on the UI foreach (var commentThread in response.Items) { commentCollection.Add(new CommentContainerDataType(methods.CommentToDataType(commentThread))); } isAdding = false; }