Esempio n. 1
0
        // Updating comment
        private static async Task UpdateComment(object commentID)
        {
            string id             = (string)commentID;
            var    youtubeService = new YouTubeService(new BaseClientService.Initializer()
            {
                ApiKey = key,
                HttpClientInitializer = credential,
                ApplicationName       = "YoutubeApp"
            });
            // Creating body of a comment with id of origin comment
            var commentThread              = new CommentThread();
            CommentThreadSnippet snippet   = new CommentThreadSnippet();
            Comment        topLevelComment = new Comment();
            CommentSnippet commentSnippet  = new CommentSnippet();

            commentSnippet.TextOriginal = GetRandomComment();
            topLevelComment.Snippet     = commentSnippet;
            snippet.TopLevelComment     = topLevelComment;
            snippet.VideoId             = VideoUrl;
            commentThread.Id            = id;
            commentThread.Snippet       = snippet;
            // Creating request and sending
            var query = youtubeService.CommentThreads.Update(commentThread, "snippet");

            try
            {
                var resp = await query.ExecuteAsync();

                Console.WriteLine("Комментарий изменен");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Esempio n. 2
0
        public async Task <CommentThread> AddComment(
            string channelId,
            string videoId,
            string text)
        {
            var comment = new CommentThread();
            var snippet = new CommentThreadSnippet
            {
                ChannelId       = channelId,
                VideoId         = videoId,
                IsPublic        = true,
                TopLevelComment = new Comment
                {
                    Snippet = new CommentSnippet
                    {
                        ChannelId    = channelId,
                        VideoId      = videoId,
                        TextOriginal = text
                    }
                }
            };

            comment.Snippet = snippet;

            var request  = this.Youtube.CommentThreads.Insert(comment, CommentParts.Snippet);
            var response = await request.ExecuteAsync();

            return(response);
        }
Esempio n. 3
0
        public async Task CommentOnVideo(string Id, string Comment)
        {
            try
            {
                LogUtil.Log($"Commenting on video with ID {Id}.");
                var youtubeService = BuildService(await BuildCredential(YouTubeService.Scope.YoutubeUpload));

                // Define the CommentThread object, which will be uploaded as the request body.
                CommentThread commentThread = new CommentThread();

                // Add the snippet object property to the CommentThread object.
                CommentThreadSnippet snippet   = new CommentThreadSnippet();
                Comment        topLevelComment = new Comment();
                CommentSnippet commentSnippet  = new CommentSnippet()
                {
                    TextOriginal = Comment
                };
                topLevelComment.Snippet = commentSnippet;
                snippet.TopLevelComment = topLevelComment;
                snippet.VideoId         = Id;
                commentThread.Snippet   = snippet;

                // Define and execute the API request
                var           request  = youtubeService.CommentThreads.Insert(commentThread, "snippet");
                CommentThread response = await request.ExecuteAsync();

                LogUtil.Log($"CommentThread responseId: {response.Id}");
            }
            catch (Exception ex)
            {
                LogUtil.Log(ex, "There was an error while commenting.");
            }
        }
Esempio n. 4
0
        public async Task <IComment> AddComment(string channelId, string videoId, string text)
        {
            if (!IsAuthorized)
            {
                return(null);
            }

            if (string.IsNullOrEmpty(text))
            {
                return(null);
            }

            // Insert channel comment by omitting videoId.
            // Create a comment snippet with text.
            var commentSnippet = new CommentSnippet {
                TextOriginal = text
            };

            // Create a top-level comment with snippet.
            var topLevelComment = new Comment {
                Snippet = commentSnippet
            };

            // Create a comment thread snippet with channelId and top-level comment.
            var commentThreadSnippet = new CommentThreadSnippet
            {
                ChannelId       = channelId,
                VideoId         = videoId,
                TopLevelComment = topLevelComment
            };

            // Create a comment thread with snippet.
            var commentThread = new CommentThread {
                Snippet = commentThreadSnippet
            };

            var youtubeService = _youTubeServiceControl.GetAuthorizedService();
            var request        = youtubeService.CommentThreads.Insert(commentThread, "snippet");

            request.Key = _youTubeServiceControl.ApiKey;

            var response = await request.ExecuteAsync();

            //небольшой хак. т.к. response не содержит текст((
            response.Snippet.TopLevelComment.Snippet.TextDisplay = text;
            return(new MComment(response));
        }
Esempio n. 5
0
        // Sending comment
        private static async Task <string> SendComment(string url)
        {
            var youtubeService = new YouTubeService(new BaseClientService.Initializer()
            {
                ApiKey = key,
                HttpClientInitializer = credential,
                ApplicationName       = "YoutubeApp"
            });

            // Making a comment
            var commentThread              = new CommentThread();
            CommentThreadSnippet snippet   = new CommentThreadSnippet();
            Comment        topLevelComment = new Comment();
            CommentSnippet commentSnippet  = new CommentSnippet();

            commentSnippet.TextOriginal = GetRandomComment();
            topLevelComment.Snippet     = commentSnippet;
            snippet.TopLevelComment     = topLevelComment;
            snippet.VideoId             = url;
            commentThread.Snippet       = snippet;
            // Sending a query
            var query = youtubeService.CommentThreads.Insert(commentThread, "snippet");

            try
            {
                var resp = await query.ExecuteAsync();

                Console.WriteLine("Комментарий отправлен");
                return(resp.Id);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            return(string.Empty);
        }