Exemplo n.º 1
0
        private static List <UserVideo> GetVideos(string channelId)
        {
            List <UserVideo> userVideos = new List <UserVideo>();

            var youtubeService = YoutubeDataApiAuth.GetYoutubeService();

            var channelsListRequest = youtubeService.Channels.List("contentDetails");

            channelsListRequest.ForUsername = channelId;

            var channelsListResponse = channelsListRequest.Execute();

            foreach (var channel in channelsListResponse.Items)
            {
                var uploadsListId = channel.ContentDetails.RelatedPlaylists.Uploads;
                var nextPageToken = "";

                var playlistItemsListRequest = youtubeService.PlaylistItems.List("snippet");
                playlistItemsListRequest.PlaylistId = uploadsListId;
                playlistItemsListRequest.MaxResults = 5;
                playlistItemsListRequest.PageToken  = nextPageToken;

                var playlistItemsListResponse = playlistItemsListRequest.Execute();
                foreach (var playlistItem in playlistItemsListResponse.Items)
                {
                    UserVideo tempVideo = new UserVideo();
                    tempVideo.VideoURL   = playlistItem.Snippet.ResourceId.VideoId;
                    tempVideo.VideoTitle = playlistItem.Snippet.Title;
                    //Video Sentiment
                    tempVideo.SentimentScore = ParseCommentThreadListResponse(YoutubeDataApiAuth.GetCommentThreadListResponse(tempVideo.VideoURL, 1));
                    userVideos.Add(tempVideo);
                }
            }
            return(userVideos);
        }
Exemplo n.º 2
0
        public AverageSentiment Get(string videoId, int maxComments)
        {
            try
            {
                // Return a new sentiment with the summary

                return(ParseCommentThreadListResponse(YoutubeDataApiAuth.GetCommentThreadListResponse(videoId, maxComments)));
            }
            catch (AggregateException ex)
            {
                // Log every exception
                foreach (var e in ex.InnerExceptions)
                {
                    _logger.LogError("Error: " + e.Message);
                }

                // Return nothing
                return(null);
            }
        }