Hi
I have below code to list my Videos. I want like,Views,Comments also to be displayed.
C#
protected void MyOwnVideos11()
{
StringBuilder htmlTable = new StringBuilder();
string nextPageToken = string.Empty;
Int32 Sr = 1;
var data = GetVideosList(nextPageToken);
var orderByPublishAt = data.items.OrderBy(x => x.snippet.publishedAt);
htmlTable.Append("");
htmlTable.Append("Sr.Video TitleDescriptionViewsLikeCommentPublished");
htmlTable.Append("");
nextPageToken = data.nextPageToken;
while (!string.IsNullOrEmpty(nextPageToken))
{
data = GetVideosList(nextPageToken);
orderByPublishAt = data.items.OrderBy(x => x.snippet.publishedAt);
nextPageToken = data.nextPageToken;
foreach (var item in orderByPublishAt)
{
htmlTable.Append("");
htmlTable.Append("" + Sr + "");
htmlTable.Append("" + item.snippet.title + "");
htmlTable.Append("" + item.snippet.description + "");
htmlTable.Append("" + item.snippet.publishedAt.ToString("dd-MM-yyyy") + "");
htmlTable.Append("");
Sr = Sr + 1;
}
}
htmlTable.Append("");
htmlTable.Append("");
PlaceHolderTable.Controls.Add(new Literal { Text = htmlTable.ToString() });
}
private static YoutubeSearchListResponse GetVideosList(string nextPageToken)
{
var client = new RestClient("googleapis.com/youtube/v3");
var request = new RestRequest("search", Method.GET);
request.AddParameter("part", "snippet");
request.AddParameter("type", "video");
request.AddParameter("channelId", "UoaVw");
request.AddParameter("key", "AIzaCFG8");
if (!string.IsNullOrEmpty(nextPageToken))
{
request.AddParameter("pageToken", nextPageToken);
}
var response = client.Execute(request);
return response.Data;
}Thanks

Sangeetha SRank #212 · 11.4K reputationPosted Apr 3, 2025, 12:48 AM EDT
Here's the updated code:
protected void MyOwnVideos11() { StringBuilder htmlTable = new StringBuilder(); string nextPageToken = string.Empty; Int32 Sr = 1; var data = GetVideosList(nextPageToken); var orderByPublishAt = data.items.OrderBy(x => x.snippet.publishedAt); htmlTable.Append(""); htmlTable.Append("Sr.Video TitleDescriptionViewsLikesCommentsPublished"); htmlTable.Append(""); nextPageToken = data.nextPageToken; while (!string.IsNullOrEmpty(nextPageToken)) { data = GetVideosList(nextPageToken); orderByPublishAt = data.items.OrderBy(x => x.snippet.publishedAt); nextPageToken = data.nextPageToken; foreach (var item in orderByPublishAt) { htmlTable.Append(""); htmlTable.Append("" + Sr + ""); htmlTable.Append("" + item.snippet.title + ""); htmlTable.Append("" + item.snippet.description + ""); htmlTable.Append("" + item.statistics.viewCount + ""); htmlTable.Append("" + item.statistics.likeCount + ""); htmlTable.Append("" + item.statistics.commentCount + ""); htmlTable.Append("" + item.snippet.publishedAt.ToString("dd-MM-yyyy") + ""); htmlTable.Append(""); Sr = Sr + 1; } } htmlTable.Append(""); htmlTable.Append(""); PlaceHolderTable.Controls.Add(new Literal { Text = htmlTable.ToString() }); } private static YoutubeSearchListResponse GetVideosList(string nextPageToken) { var client = new RestClient("https://www.googleapis.com/youtube/v3"); var request = new RestRequest("search", Method.GET); request.AddParameter("part", "snippet,statistics"); request.AddParameter("type", "video"); request.AddParameter("channelId", "UoaVw"); request.AddParameter("key", "AIzaCFG8"); if (!string.IsNullOrEmpty(nextPageToken)) { request.AddParameter("pageToken", nextPageToken); } var response = client.Execute(request); return response.Data; }This code will now include the view count, like count, and comment count for each video in your HTML table.