Skip to main content
Login Register
Code2night
  • Home
  • Blog Archive
  • Learn
    • Tutorials
    • Videos
  • Interview Q&A
  • Resources
    • Cheatsheets
    • Tech Comparisons
  • Languages
    • Angular Angular js ASP.NET Asp.net Core ASP.NET Core, C# ASP.NET MVC ASP.NET Web Forms C C# C#, ASP.NET Core, Dapper
      C#, ASP.NET Core, Dapper, Entity Framework DotNet General Web Development HTML, CSS HTML/CSS Java JavaScript JavaScript, HTML, CSS JavaScript, Node.js Node.js
      Python Python 3.11, Pandas, SQL Python 3.11, SQL Python 3.11, SQLAlchemy Python 3.11, SQLAlchemy, SQL Python 3.11, SQLite React Security SQL Server TypeScript
  • Post Blog
  • Tools
    • Beautifiers
      JSON Beautifier HTML Beautifier XML Beautifier CSS Beautifier JS Beautifier SQL Formatter
      Dev Utilities
      JWT Decoder Regex Tester Diff Checker Cron Explainer String Escape Hash Generator Password Generator
      Converters
      Base64 Encode/Decode URL Encoder/Decoder JSON to CSV CSV to JSON JSON to TypeScript Markdown to HTML Number Base Converter Timestamp Converter Case Converter
      Generators
      UUID / GUID Generator Lorem Ipsum QR Code Generator Meta Tag Generator
      Image Tools
      Image Converter Image Resizer Image Compressor Image to Base64 PNG to ICO Background Remover Color Picker
      Text & Content
      Word Counter PDF Editor
      SEO & Web
      SEO Analyzer URL Checker World Clock
  1. Home
  2. Blog
  3. ASP.NET Core
  4. Get Channel Comments using YouTube Data Api in Asp.Net

Get Channel Comments using YouTube Data Api in Asp.Net

Date- May 13,2023 Updated Mar 2026 5309 Free Download Pay & Download
YouTube Api Aspnet

Hello, guys, and welcome to Code2Night! Are you looking to enhance your website by displaying comments from your YouTube channel? Well, you're in luck! In this tutorial, we will guide you through the process of retrieving channel comments using the YouTube Data API in Asp.Net.

As content creators, engaging with our audience is crucial, and what better way to do so than by showcasing their valuable comments on our own websites? By leveraging the power of the YouTube Data API, we can easily access and display these comments in our Asp.Net applications.

Throughout this tutorial, we will walk you through the necessary steps to integrate the YouTube Data API into your Asp.Net project. We will cover everything from setting up the API credentials to making API requests and handling the retrieved comments.

Whether you're a seasoned developer or just starting out, this tutorial will provide you with a clear understanding of how to utilize the YouTube Data API to fetch channel comments and incorporate them into your Asp.Net web applications.

So, let's dive right in and learn how to harness the potential of the YouTube Data API to enrich your website with real-time comments from your YouTube channel. By the end of this tutorial, you'll have the knowledge and skills to seamlessly integrate channel comments into your Asp.Net projects.

Let's get started and unlock the power of the YouTube Data API together!

We sometimes need to get comments from our YouTube channel and display them on our websites. So, in this tutorial, we will show you how to get YouTube channel comments using YouTube Data API in Asp.Net.

YouTube provides the YouTube Data API v3, which allows us to obtain information about YouTube videos or channels. In order to use this API, we need to obtain an API key from Google. The first step is to obtain a key for the YouTube Data API from Google.

So, once you have the key now go to your Asp.Net MVC application and go to

youtubeNow, after clicking on "Manage NuGet Packages," you need to search for "Google.Apis.YouTube.v3," which you can see in the screenshot below. You must install this NuGet package.

Get Channel Comments using YouTube Data Api in AspNet

Once you have installed the NuGet package what you have to do is go to your Asp.net MVC application.

Now you have to create the model that we will use to show data on the view, you create one class file and paste the following code

using Google.Apis.Services;
using Google.Apis.YouTube.v3;
using Google.Apis.YouTube.v3.Data;

Now you have to paste the following code into your controller. In this, you will notice we have used two values " apikey"="" and="" "channelid"="" from="" web.config.="" you="" can="" put="" your="" static="" values="" here.<="" p="">

public ActionResult Index()
        {
         
            var yt = new YouTubeService(new BaseClientService.Initializer() { ApiKey = ConfigurationManager.AppSettings["ApiKey"].ToString() });
            var channelsListRequest = yt.Channels.List("contentDetails");
            channelsListRequest.Id = ConfigurationManager.AppSettings["ChannelId"].ToString() ;
            
            var channelsListResponse = channelsListRequest.Execute();
           
            List<Comments> CommentList = new List<Comments>();
            foreach (var channel in channelsListResponse.Items)
            {
                var uploadsListId = channel.ContentDetails.RelatedPlaylists.Uploads;
                var nextPageToken = "";
                while (nextPageToken != null)
                {
                   var commentslist= yt.CommentThreads.List("snippet");
                   commentslist.AllThreadsRelatedToChannelId = ConfigurationManager.AppSettings["ChannelId"].ToString();
                    commentslist.MaxResults = 50;
                    commentslist.PageToken = nextPageToken;
                    var commentresponse = commentslist.Execute();
                    foreach (var commentItem in commentresponse.Items)
                    {
                        var commentText = commentItem.Snippet.TopLevelComment.Snippet.TextOriginal;
                        var user = commentItem.Snippet.TopLevelComment.Snippet.AuthorDisplayName;
                        var video = commentItem.Snippet.VideoId;
                        var publishedate = commentItem.Snippet.TopLevelComment.Snippet.PublishedAt ;
                        var userimage = commentItem.Snippet.TopLevelComment.Snippet.AuthorProfileImageUrl;
                        var ispublic = commentItem.Snippet.IsPublic;
                        CommentList.Add(new Comments
                        {
                            Comment = commentText,
                            UserImageUrl = userimage,
                            CommentedBy = user,
                            CommentedOn = publishedate,
                            VideoId= video
                        });
                        
                    }
                    nextPageToken = commentresponse.NextPageToken;
                 
                }
              
            }
            return View(CommentList);
        }

Now you have to create the model that we will use to show data on the view, you create one class file and paste the following code

 public class Comments
    {
        public string Comment { get; set; }
        public string CommentedBy { get; set; }
        public DateTime? CommentedOn { get; set; }
        public string VideoId { get; set; }
        public string UserImageUrl { get; set; }
    }

So, now the only required part is the Web. config changes, so you can add the following keys in the app settings

<add key="ChannelId" value="UCqQGu4auPacvpkoAFuZvew" />
	  <add key="ApiKey" value="AIzaSyC5Q-KPeaW932VAjpkfda96pOfQNwTltsY" />

These keys and channelId are dummies and will not work, so you have to replace these with your original channeled and API key. Now you have to go to the view and follow the code to show the data on the view

@model List<YouTubeApiDemo.Models.Comments>
@{
    ViewBag.Title = "Home Page";
}


<div>
    @foreach (var item in Model)
    {
        <div class="col-md-12" style="padding:5px;border:1px solid grey;margin-bottom:5px;">
           
            <div class="col-md-10">
                <h3> @item.Comment</h3>
                <p> @item.CommentedBy</p>
            </div>
        </div>
    }
    </div>

After using this now we are ready to run the application. Now run the application and check the output on the browser it will show something like this

Get Channel Comments using YouTube Data Api in AspNet 2

So this is how we can get the comments from youtube in Asp.Net.

S
Shubham Batra
Programming author at Code2Night — sharing tutorials on ASP.NET, C#, and more.
View all posts →

Related Articles

Get Channel Videos using YouTube Data Api in Asp.Net
Apr 13, 2023
Mastering ARIA Roles for Enhanced Accessibility in ASP.NET Applications
Apr 09, 2026
Best Practices for Secure Gemini API Integration in ASP.NET
Apr 03, 2026
How to Import CSV in ASP.NET MVC
Feb 02, 2024
Previous in ASP.NET Core
Get Channel Videos using YouTube Data Api in Asp.Net
Next in ASP.NET Core
Login With Microsoft in Asp.net
Buy me a pizza

Comments

🔥 Trending This Month

  • 1
    HTTP Error 500.32 Failed to load ASP NET Core runtime 6,933 views
  • 2
    Error-An error occurred while processing your request in .… 11,269 views
  • 3
    Comprehensive Guide to Error Handling in Express.js 233 views
  • 4
    ConfigurationBuilder does not contain a definition for Set… 19,458 views
  • 5
    Mastering JavaScript Error Handling with Try, Catch, and F… 160 views
  • 6
    Mastering Unconditional Statements in C: A Complete Guide … 21,491 views
  • 7
    Unable to connect to any of the specified MySQL hosts 6,225 views

On this page

🎯

Interview Prep

Ace your ASP.NET Core interview with curated Q&As for all levels.

View ASP.NET Core Interview Q&As

More in ASP.NET Core

  • How to Encrypt and Decrypt Password in Asp.Net 26063 views
  • Exception Handling Asp.Net Core 20794 views
  • HTTP Error 500.31 Failed to load ASP NET Core runtime 20287 views
  • How to implement Paypal in Asp.Net Core 19675 views
  • Task Scheduler in Asp.Net core 17576 views
View all ASP.NET Core posts →

Tags

AspNet C# programming AspNet MVC c programming AspNet Core C software development tutorial MVC memory management Paypal coding coding best practices data structures programming tutorial tutorials object oriented programming Slick Slider StripeNet
Free Download for Youtube Subscribers!

First click on Subscribe Now and then subscribe the channel and come back here.
Then Click on "Verify and Download" button for download link

Subscribe Now | 1770
Download
Support Us....!

Please Subscribe to support us

Thank you for Downloading....!

Please Subscribe to support us

Continue with Downloading
Be a Member
Join Us On Whatsapp
Code2Night

A community platform for sharing programming knowledge, tutorials, and blogs. Learn, write, and grow with developers worldwide.

Panipat, Haryana, India
info@code2night.com
Quick Links
  • Home
  • Blog Archive
  • Tutorials
  • About Us
  • Contact
  • Privacy Policy
  • Terms & Conditions
  • Guest Posts
  • SEO Analyzer
Dev Tools
  • JSON Beautifier
  • HTML Beautifier
  • CSS Beautifier
  • JS Beautifier
  • SQL Formatter
  • Diff Checker
  • Regex Tester
  • Markdown to HTML
  • Word Counter
More Tools
  • Password Generator
  • QR Code Generator
  • Hash Generator
  • Base64 Encoder
  • JWT Decoder
  • UUID Generator
  • Image Converter
  • PNG to ICO
  • SEO Analyzer
By Language
  • Angular
  • Angular js
  • ASP.NET
  • Asp.net Core
  • ASP.NET Core, C#
  • ASP.NET MVC
  • ASP.NET Web Forms
  • C
  • C#
  • C#, ASP.NET Core, Dapper
  • C#, ASP.NET Core, Dapper, Entity Framework
  • DotNet
  • General Web Development
  • HTML, CSS
  • HTML/CSS
  • Java
  • JavaScript
  • JavaScript, HTML, CSS
  • JavaScript, Node.js
  • Node.js
  • Python
  • Python 3.11, Pandas, SQL
  • Python 3.11, SQL
  • Python 3.11, SQLAlchemy
  • Python 3.11, SQLAlchemy, SQL
  • Python 3.11, SQLite
  • React
  • Security
  • SQL Server
  • TypeScript
© 2026 Code2Night. All Rights Reserved.
Made with for developers  |  Privacy  ·  Terms
Translate Page
We use cookies to improve your experience and analyze site traffic. By clicking Accept, you consent to our use of cookies. Privacy Policy
Accessibility
Text size
High contrast
Grayscale
Dyslexia font
Highlight links
Pause animations
Large cursor