Hi
I have below code which list my videos. I want that description of all videos should be updated with Title
protected void MyOwnVideos()
{
StringBuilder htmlTable = new StringBuilder();
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", "UC_nNoaVw"); // Replace with your actual channelId
request.AddParameter("key", "AIz8..."); // Replace with your actual API key
IRestResponse response = client.Execute(request);
// Check if the response contains data
if (response.Data == null || response.Data.items == null || response.Data.items.Count == 0)
{
Console.WriteLine("No Data Found. Please check your channelId and API key.");
return;
}
// Build the HTML table
htmlTable.Append("");
htmlTable.Append("Video Id Video Title Description Published ");
htmlTable.Append("");
foreach (var data in response.Data.items.OrderBy(x => x.snippet.publishedAt))
{
htmlTable.Append("");
htmlTable.Append($"{data.id} ");
htmlTable.Append($"{data.snippet.title} ");
htmlTable.Append($"{data.snippet.description} ");
htmlTable.Append($"{data.snippet.publishedAt} ");
htmlTable.Append(" ");
}
htmlTable.Append("");
htmlTable.Append("
");
// Output the HTML table
Console.WriteLine(htmlTable.ToString());
}
public class YoutubeSearchListResponse
{
public string kind { get; set; }
public string etag { get; set; }
public string nextPageToken { get; set; }
public string regionCode { get; set; }
public PageInfo pageInfo { get; set; }
public List- items { get; set; }
}
public class Snippet
{
public DateTime publishedAt { get; set; }
public string channelId { get; set; }
public string title { get; set; }
public string description { get; set; }
public Thumbnail thumbnails { get; set; }
public string channelTitle { get; set; }
public string liveBroadcastContent { get; set; }
public DateTime publishTime { get; set; }
}
public class Id
{
public string kind { get; set; }
public string videoId { get; set; }
}
public class Item
{
public string kind { get; set; }
public string etag { get; set; }
public Id id { get; set; }
public Snippet snippet { get; set; }
}
Thanks
Muhammad Imran AnsariPosted Mar 21, 2025, 1:27 AM
Hello Ramco,
To update the description of all videos with their title, modify the
snippet.descriptionfield in your loop before appending the data to the table. Here's the updated code:This will replace each video's description with its title before displaying it. If you need to update the descriptions permanently on YouTube, you will need to make a separate API request to update each video’s metadata using the YouTube Data API (Videos: update method). Let me know if you need help with that.
Good Luck!
Sophia CarterPosted Mar 21, 2025, 12:55 AM
Hi
The code you provided outlines a method called `MyOwnVideos` that fetches videos based on a specified YouTube channel ID using the YouTube Data API. The method constructs an HTML table displaying details of each video, including Video ID, Video Title, Description, and Published Date.
To update the description of all videos with the title, you can modify the code within the `foreach` loop where the HTML table rows are being constructed. Instead of displaying `data.snippet.description`, you would need to replace it with `data.snippet.title` to show the video title as the description in the table.
Here's the specific part of the code that needs modification:
By making the above change, the Description column in your HTML table will now reflect the title of each video instead of the actual description. This adjustment aligns with your objective of updating the descriptions with titles.
If you have any further questions or need additional clarification, feel free to ask. Good luck with your video listing project!