Hi
I have below code of list if videos. I want to get Youtube Search Terms of each video
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());
}
Thanks
Sophia CarterPosted Mar 21, 2025, 3:34 PM
Based on the code provided, it seems that you are trying to retrieve a list of videos from a specific YouTube channel using the YouTube Data API v3. To extract the search terms or keywords associated with each video, you can access the `snippet` object within each `data` item in the response.
Here's how you can modify your existing code snippet to extract the search terms for each video:
1. Within the `foreach` loop, you can access the `tags` property under `snippet`. This property contains an array of strings that represent keywords or tags associated with the video.
2. You can then iterate over the `tags` array to retrieve individual search terms for each video.
Below is an example of how you can modify the existing code snippet to include the search terms of each video:
By including the above modification, you should be able to display the search terms associated with each video alongside its other details in the HTML table. This way, you can easily access and showcase the search terms of each video retrieved from the YouTube Data API response.
If you have any further questions or need additional clarification, feel free to ask!