Hi Jayraj
I am trying like below . How further to be done. I want to display Channel Name,Video Title,Description,Search Keywords of that video
C#
var clientTag = new RestClient("googleapis.com/youtube/v3/");
var tagRequest = new RestRequest("videos", Method.GET);
tagRequest.AddParameter("key", "AIzaSyKSHDHYDHDYD6Q9b5LsKYHT8");Thanks

Jayraj ChhayaRank #304 · 8.2K reputationPosted Apr 5, 2024, 5:09 AM EDT
To achieve this, you need to make a request to the YouTube Data API endpoint for videos and specify the
partparameter to include the information you need (e.g., snippet). Additionally, you can use theidparameter to specify the video ID for the video you are interested in.var clientTag = new RestClient("https://www.googleapis.com/youtube/v3/"); var tagRequest = new RestRequest("videos", Method.GET); tagRequest.AddParameter("key", "YOUR_API_KEY"); tagRequest.AddParameter("part", "snippet"); tagRequest.AddParameter("id", "YOUR_VIDEO_ID"); var response = clientTag.Execute(tagRequest); var content = response.Content; // Parse the JSON response to extract Channel Name, Video Title, Description, and Search Keywords // Example parsing code will depend on the JSON structure returned by the APIRamco RamcoRank #462 · 5.4K reputationPosted Apr 5, 2024, 6:27 AM EDT
Hi
I am getting below error. I want to loop through all my Short Videos.
{ "error": { "code": 400, "message": "No filter selected. Expected one of: myRating, id, chart", "errors": [ { "message": "No filter selected. Expected one of: myRating, id, chart", "domain": "youtube.parameter", "reason": "missingRequiredParameter", "location": "parameters.", "locationType": "other" } ] } }Below is the code
var clientTag = new RestClient("https://www.googleapis.com/youtube/v3/"); var tagRequest = new RestRequest("videos", Method.GET); tagRequest.AddParameter("key", "AIzKSHHDHGDt6cGJDKDJQ9b5Ls8EDISJ8"); tagRequest.AddParameter("part", "snippet"); //tagRequest.AddParameter("id", "YOUR_VIDEO_ID"); var response = clientTag.Execute(tagRequest); var content = response.Content;Thanks
Naimish MakwanaRank #324 · 7.7K reputationPosted Apr 5, 2024, 6:38 AM EDT
The error message indicates that the YouTube API expects a filter parameter, such as
myRating,id, orchart. In your case, you’re trying to get details of videos, so you should use theidparameter. However, you’ve commented out the line where you add theidparameter.If you want to loop through all your short videos, you need to have a list of all the video IDs. Once you have this list, you can loop through it and make a request for each video ID.
Here’s an example of how you can do it:
var clientTag = new RestClient("https://www.googleapis.com/youtube/v3/"); var tagRequest = new RestRequest("videos", Method.GET); tagRequest.AddParameter("key", "AIzKSHHDHGDt6cGJDKDJQ9b5Ls8EDISJ8"); tagRequest.AddParameter("part", "snippet"); // Assuming you have a list of video IDs List videoIds = new List { "videoId1", "videoId2", "videoId3" }; // replace with your video ids foreach (var videoId in videoIds) { tagRequest.AddParameter("id", videoId); var response = clientTag.Execute(tagRequest); var content = response.Content; // Deserialize the JSON response var videoDetails = JsonConvert.DeserializeObject(content); // Extract the required details var channelName = videoDetails["items"][0]["snippet"]["channelTitle"]; var videoTitle = videoDetails["items"][0]["snippet"]["title"]; var description = videoDetails["items"][0]["snippet"]["description"]; var tags = videoDetails["items"][0]["snippet"]["tags"]; // this is a list of tags // Do something with the details... }Please replace
"videoId1","videoId2","videoId3"with your actual video IDs. This code will loop through each video ID in the list, make a request to the YouTube API, and extract the required details.Remember to handle potential exceptions and errors in your code. This includes checking if the video id is valid and handling the case where the video might not have any tags.
Note: Be careful not to expose your API key (
AIzKSHHDHGDt6cGJDKDJQ9b5Ls8EDISJ8) in a public or insecure environment, as it could be used by others to access your Google API services. It’s always a good practice to store sensitive information like this in a secure way (like environment variables or secure app config).Thanks
Ramco RamcoRank #462 · 5.4K reputationPosted Apr 5, 2024, 6:46 AM EDT
Hi Naimish
I am getting error IRestResponse does not contain a definition for data. Secondly i want to get Search Keywordsof my Videos
List listVideo = new List(); var clientTag = new RestClient("youtube/v3/"); var tagRequest = new RestRequest("videos", Method.GET); tagRequest.AddParameter("key", "AIz8"); tagRequest.AddParameter("part", "snippet"); tagRequest.AddParameter("q", "sports shorts"); tagRequest.AddParameter("type", "video"); tagRequest.AddParameter("videoDuration", "short"); var response = clientTag.Execute(tagRequest); foreach (var searchResult in response.Data.items) { listVideo.Add(searchResult); }Thanks
Naimish MakwanaRank #324 · 7.7K reputationPosted Apr 5, 2024, 6:55 AM EDT
Please try below code.
public class SearchListResponse { public string Kind { get; set; } public string Etag { get; set; } public string NextPageToken { get; set; } public PageInfo PageInfo { get; set; } public List Items { get; set; } } public class SearchResult { public string Kind { get; set; } public string Etag { get; set; } public Id Id { get; set; } public Snippet Snippet { get; set; } } public class PageInfo { public int TotalResults { get; set; } public int ResultsPerPage { get; set; } } public class Id { public string Kind { get; set; } public string VideoId { 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 Thumbnails Thumbnails { get; set; } public string ChannelTitle { get; set; } public string LiveBroadcastContent { get; set; } } public class Thumbnails { public Thumbnail Default { get; set; } public Thumbnail Medium { get; set; } public Thumbnail High { get; set; } } public class Thumbnail { public string Url { get; set; } public int Width { get; set; } public int Height { get; set; } }And here’s how you can use these classes with your existing code:
var clientTag = new RestClient("https://www.googleapis.com/youtube/v3/"); var tagRequest = new RestRequest("search", Method.GET); tagRequest.AddParameter("key", "AIz8"); tagRequest.AddParameter("part", "snippet"); tagRequest.AddParameter("q", "sports shorts"); tagRequest.AddParameter("type", "video"); tagRequest.AddParameter("videoDuration", "short"); var response = clientTag.Execute(tagRequest); List listVideo = new List(); foreach (var searchResult in response.Data.Items) { listVideo.Add(searchResult); }Please note that this code assumes that you have the
RestSharpandNewtonsoft.Jsonlibraries installed in your project. If not, you can install them via NuGet Package Manager.Thanks
Ramco RamcoRank #462 · 5.4K reputationPosted Apr 5, 2024, 7:11 AM EDT
Hi Naimish
Can u pls help according to my code. Is it possible through below code that i will be able to get Search Keywords Video Wise
List listVideo = new List(); var client = new RestClient("youtube/v3"); var request = new RestRequest("search", Method.GET); request.AddParameter("part", "snippet"); request.AddParameter("q", "sports shorts"); request.AddParameter("type", "video"); request.AddParameter("videoDuration", "short"); request.AddParameter("key", "AIJHDKSY9"); var response = client.Execute(request); foreach (var data in response.Data.items) { var clientTag0 = new RestClient("https://www.googleapis.com/youtube/v3/"); var tagRequest0 = new RestRequest("videos", Method.GET); tagRequest0.AddParameter("key", "AIzaSyA9"); tagRequest0.AddParameter("part", "snippet,statistics"); tagRequest0.AddParameter("order", "viewCount"); tagRequest0.AddParameter("id", data.id.videoId); var tagResponse0 = clientTag0.Execute(tagRequest0); foreach (var searchResult in tagResponse0.Data.items) { listVideo.Add(searchResult); } }Thanks
Naimish MakwanaRank #324 · 7.7K reputationPosted Apr 5, 2024, 7:37 AM EDT
Yes, your code is almost correct. You’re correctly using the
searchendpoint to get a list of videos and then using thevideosendpoint to get the details of each video. However, you need to make sure that thesnippetpart is included in thepartparameter when you’re making the request to thevideosendpoint, as thetagsfield is part of thesnippet.Here’s how you can modify your code to get the search keywords (tags) of each video:
List listVideo = new List(); var client = new RestClient("https://www.googleapis.com/youtube/v3"); var request = new RestRequest("search", Method.GET); request.AddParameter("part", "snippet"); request.AddParameter("q", "sports shorts"); request.AddParameter("type", "video"); request.AddParameter("videoDuration", "short"); request.AddParameter("key", "AIJHDKSY9"); var response = client.Execute(request); foreach (var data in response.Data.items) { var clientTag0 = new RestClient("https://www.googleapis.com/youtube/v3/"); var tagRequest0 = new RestRequest("videos", Method.GET); tagRequest0.AddParameter("key", "AIzaSyA9"); tagRequest0.AddParameter("part", "snippet,statistics"); tagRequest0.AddParameter("id", data.id.videoId); var tagResponse0 = clientTag0.Execute(tagRequest0); foreach (var searchResult in tagResponse0.Data.items) { listVideo.Add(searchResult); var tags = searchResult.snippet.tags; // this is a list of tags (search keywords) // Do something with the tags... } }In this code,
YoutubeSearchListResponse,VideoListResponse, andItemare classes that represent the structure of the API response. You need to define these classes according to the API response structure.Please note that the YouTube Data API does not provide the search keywords of a video directly. The
tagsfield in thesnippetof a video resource contains the keywords of the video, but this field is only included for videos that are owned by the authenticated user. If you want to get the keywords of your videos, you need to authenticate with OAuth 2.0 and use thevideos.listmethod with theidparameter set to the IDs of your videos.Thanks
Ramco RamcoRank #462 · 5.4K reputationPosted Apr 5, 2024, 7:51 AM EDT
Hi Naimish
I want to get these keywords . Secondly to start with i want my own videos. What changes i need to do.
Thanks