Example #1
0
        private async Task <string> GetYtNameByChannelId(string id)
        {
            try
            {
                if (string.IsNullOrEmpty(_ytKey))
                {
                    throw new Exception("Api key is null or empty");
                }
                var response = await _youtubeService.GetChannelById(id);

                if (response.Items.Any())
                {
                    return(response.Items[0].Snippet.Title);
                }

                throw new InvalidDataException($"Snippet fo channel with id = {id} not found");
            }
            catch (Exception ex)
            {
                var mes = ex.InnerException != null ? ex.InnerException.Message : ex.Message;
                throw new Exception($"Trying youtube channel name by id ({id}) has been failded : {mes}");
            }
        }