Hi
In below code i want to get Tags,Country etc.
public void ShortVideosSports()
{
Int32 Count = 1;
StringBuilder htmlTable = new StringBuilder();
List listVideo = new List();
var client = new RestClient("youtube/v3");
var request = new RestRequest("search", Method.GET);
request.AddParameter("part", "snippet");
request.AddParameter("type", "video");
request.AddParameter("order", "viewCount");
DateTime twoDaysAgo = DateTime.UtcNow.AddDays(-2);
string publishedAfter = twoDaysAgo.ToString("yyyy-MM-dd'T'HH:mm:ss'Z'");
request.AddParameter("publishedAfter", publishedAfter);
request.AddParameter("key", "AJSTHSSTHSSG8");
var response = client.Execute(request);
Int32 ViewCount = 0;
foreach (var data in response.Data.items)
{
var clientTag0 = new RestClient("youtube/v3/");
var tagRequest0 = new RestRequest("videos", Method.GET);
tagRequest0.AddParameter("key", "AIJSGSTSGYTSJSHHSGs8ECFG8");
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);
}
}
if (listVideo.Any())
{
htmlTable.Append("");
//htmlTable.Append("SN Description Tags ");
htmlTable.Append("SN Channel Id Channel Title Video Title Description Views Published ");
htmlTable.Append("");
var orderByVideosCount = listVideo.OrderByDescending(x => x.statistics.viewCount);
foreach (var item in orderByVideosCount)
{
htmlTable.Append("" + Count.ToString() + " ");
htmlTable.Append("" + item.snippet.description + " ");
htmlTable.Append("" + item.statistics.viewCount + " ");
htmlTable.Append("");
Count++;
}
htmlTable.Append("");
htmlTable.Append("
");
PlaceHolderTable.Controls.Add(new Literal { Text = htmlTable.ToString() });
}
}
Thanks
Naimish MakwanaPosted Apr 3, 2024, 11:03 AM
The code you’ve provided is using the YouTube Data API to fetch a list of videos and their details. However, it seems like you’re not currently retrieving the tags or the country of the videos. Here’s how you can modify your code to get these details:
To get the tags of a video, you need to make sure that the
partparameter in your request includessnippet. The tags of a video can be found in thesnippetpart of the video resource12. In your code, you are already requesting thesnippetpart, so the tags should be available insearchResult.snippet.tags.However, please note that as of YouTube Data API v3, the tags of a video are only returned for the video uploader. That means you can only retrieve the tags of a video if the request is authorized by the owner of the video2.
As for the country, the YouTube Data API does not provide a direct way to get the country of a video. The API used to have a
regionCodeparameter, but it was for instructing the API to return a video chart available in a specific region, not for getting the country of a video3. The country of the channel that uploaded the video might be available, but this is not guaranteed and it also doesn’t necessarily represent the country of the video itself4.If you need more specific information about a video, such as its geographic location, you might need to look into other sources or APIs. Always ensure that you respect user privacy and terms of service when accessing and using such data.
Here’s an example of how you can access the tags from the
searchResult:This will print out all the tags of each video. Remember, this will only work if the request is authorized by the owner of the video.