Hi
I have below code and i want to get Search List of Video also
protected void MyOwnVideos11()
{
StringBuilder htmlTable = new StringBuilder();
string nextPageToken = string.Empty;
Int32 Sr = 1;
var client = new RestClient("googleapis.com/youtube/v3");
var request = new RestRequest("search", Method.GET);
request.AddParameter("type", "video");
request.AddParameter("channelId", "UC_nNoaVw);
request.AddParameter("key", "AIz8...");
if (!string.IsNullOrEmpty(nextPageToken))
{
request.AddParameter("pageToken", nextPageToken);
}
var response = client.Execute(request);
var orderByPublishAt = response.Data.items.OrderBy(x => x.snippet.publishedAt);
htmlTable.Append("");
htmlTable.Append("Sr. Video Title Description Published ");
htmlTable.Append("");
do
{
foreach (var data in orderByPublishAt)
{
var clientTag = new RestClient("googleapis.com/youtube/v3/");
var tagRequest = new RestRequest("videos", Method.GET);
tagRequest.AddParameter("key", "AIz8...");
tagRequest.AddParameter("part", "snippet,statistics");
tagRequest.AddParameter("id", data.id.videoId);
var tagResponse = clientTag.Execute(tagRequest);
foreach (var item in tagResponse.Data.items)
{
htmlTable.Append("" + Sr + " ");
htmlTable.Append("" + item.snippet.title + " ");
htmlTable.Append("" + item.snippet.description + " ");
htmlTable.Append("" + data.snippet.publishedAt.ToString("dd-MM-yyyy") + " ");
htmlTable.Append("");
}
Sr = Sr + 1;
nextPageToken = response.Data.nextPageToken;
}
} while (!string.IsNullOrEmpty(nextPageToken));
htmlTable.Append(" ");
htmlTable.Append("
");
PlaceHolderTable.Controls.Add(new Literal { Text = htmlTable.ToString() });
}
Thanks
sasikala sPosted Mar 26, 2025, 5:35 AM
want to fetch a list of videos from a specific YouTube channel and display them in an HTML table. Here are a few improvements and corrections to your code:
channelIdparameter: ThechannelIdvalue is missing a closing quote.do-whileloop should continue fetching data untilnextPageTokenis empty..Here's the revised code:
Sophia CarterPosted Mar 26, 2025, 1:35 AM
It appears that you are looking to retrieve a list of videos using the YouTube Data API in C#. The code snippet you provided seems to be aimed at fetching video information based on specific parameters like channel ID and API key. Here's a breakdown of the key points in your code:
1. The `MyOwnVideos11` method is used to fetch video details from the YouTube API.
2. It utilizes the RestClient library to make HTTP requests to the YouTube Data API endpoint.
3. The request is made to the `"search"` endpoint of the YouTube Data API with parameters like video type, channelId, and API key.
4. The response is then processed to extract useful information like video titles, descriptions, and publication dates.
5. There is a loop implemented to handle pagination and iterate through the search results.
6. For each video found in the search results, additional information is fetched using the video ID.
A couple of points to consider for improvement or further understanding:
- Ensure that you handle exceptions and errors in the API requests for robustness.
- Make sure to properly handle pagination if there are more search results than can be retrieved in a single request.
If you encounter any specific issues or need further clarification on any part of the code or YouTube Data API usage, feel free to ask for more details or assistance.