Hi
I have below code to list my Videos. I want like,Views,Comments also to be displayed.
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 Title Description Views Like Comment Published ");
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 SPosted Apr 3, 2025, 4:48 AM
Here's the updated code:
This code will now include the view count, like count, and comment count for each video in your HTML table.