Hi
How to get search keywords of my own youtube videos
C#
List listVideo = new List();
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("maxResults", 100);
request.AddParameter("sortOrder", "desc");
request.AddParameter("key", "AIzaSyCFG8");
var response = client.Execute(request);
htmlTable.Append("");
htmlTable.Append("SNChannel Id / TitleVideo TitleDescriptionCategoryView CountPublished");
htmlTable.Append("");
Int32 ViewCount = 0;
foreach (var data in response.Data.items)
{
var clientTag0 = new RestClient("googleapis.com/youtube/v3/");
var tagRequest0 = new RestRequest("videos", Method.GET);
tagRequest0.AddParameter("key", "AIzaSG8");
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);
}
}
if (listVideo.Any())Thanks

Prasad RaveendranRank #320 · 7.8K reputationPosted Jun 17, 2024, 10:18 PM EDT
using System; using System.Collections.Generic; using System.Linq; using RestSharp; using YourNamespace.Models; // Ensure this is the namespace where VideoListResponse and YoutubeSearchListResponse are defined 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("type", "video"); request.AddParameter("maxResults", 100); request.AddParameter("sortOrder", "desc"); request.AddParameter("key", "YOUR_API_KEY"); var response = client.Execute(request); StringBuilder htmlTable = new StringBuilder(); htmlTable.Append(""); htmlTable.Append("SNChannel Id / TitleVideo TitleDescriptionCategoryView CountPublishedTags"); htmlTable.Append(""); Int32 ViewCount = 0; 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", "YOUR_API_KEY"); 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); // Extract tags from the snippet var tags = searchResult.snippet.tags != null ? string.Join(", ", searchResult.snippet.tags) : "No tags"; htmlTable.Append($"{++ViewCount}{searchResult.snippet.channelId} / {searchResult.snippet.channelTitle}{searchResult.snippet.title}{searchResult.snippet.description}{searchResult.snippet.categoryId}{searchResult.statistics.viewCount}{searchResult.snippet.publishedAt}{tags}"); } } htmlTable.Append(""); if (listVideo.Any()) { // Your logic to display or use the htmlTable } // Define your VideoListResponse and YoutubeSearchListResponse classes public class VideoListResponse { public List items { get; set; } public class Item { public Snippet snippet { get; set; } public Statistics statistics { get; set; } public class Snippet { public string channelId { get; set; } public string channelTitle { get; set; } public string title { get; set; } public string description { get; set; } public string categoryId { get; set; } public DateTime publishedAt { get; set; } public List tags { get; set; } } public class Statistics { public long viewCount { get; set; } } } } public class YoutubeSearchListResponse { public List items { get; set; } public class Item { public Id id { get; set; } public class Id { public string videoId { get; set; } } } }o retrieve the search keywords (tags) of your own YouTube videos using the YouTube Data API, you need to make a request to the
videosendpoint and include thesnippetpart in your request parameters. Here's a step-by-step guide to modifying your existing code to fetch and display these keywords:-
-
-
Explanation:Modify your request to include the
tagsfield in thesnippetpart: Ensure thepartparameter in yourvideosrequest includessnippetso that you can access the tags of the videos.Extract the tags from the response: After receiving the response from the
videosendpoint, extract thetagsfield from thesnippetobject of each video.Display the tags: Append the tags to your HTML table or any other preferred output format.
API Client Initialization: Initialize the
RestClientwith the YouTube Data API base URL (https://www.googleapis.com/youtube/v3).Search Request Setup: Set up the search request to get a list of video IDs from your channel.
Videos Request Setup: For each video ID obtained from the search response, set up another request to get detailed information about the video, including the
tags.HTML Table Construction: Construct an HTML table to display the video information along with their tags.
Data Models: Ensure you have the
VideoListResponseandYoutubeSearchListResponseclasses correctly defined to deserialize the API responses.Make sure to replace
"YOUR_API_KEY"with your actual YouTube Data API key.Prasad RaveendranRank #320 · 7.8K reputationPosted Jun 30, 2024, 3:50 PM EDT
If you're not receiving tags for your own videos despite using the correct API calls, there are a few potential issues to consider and steps to troubleshoot:
Permissions and OAuth2 Scope: Ensure that your OAuth2 token has the correct scope (
https://www.googleapis.com/auth/youtube.readonlyor broader scopes likehttps://www.googleapis.com/auth/youtubeif necessary) to access your videos' tags. If the scope is too restrictive, it may prevent fetching detailed video information.Video Privacy Settings: Check the privacy settings of your videos. If your videos are private or unlisted, they may not be accessible through the API unless you have authenticated with the appropriate permissions.
API Quotas and Limits: Verify that you haven't exceeded API quotas or limits. Google APIs have daily quotas that restrict the number of requests you can make per day. Ensure you are within your quota limits to receive complete responses.
Error Handling: Implement proper error handling to capture any API errors or exceptions that may occur during the request. This will help identify specific issues such as authentication failures or quota limits.
Verify API Responses: Log or inspect the API responses (
tagResponse0in your case) to ensure that theitemsreturned actually contain the tags (snippet.tags) you expect. Sometimes, videos may not have tags, or there could be issues with how data is processed or displayed.Here’s a checklist to help debug your implementation:
Check OAuth2 Scope: Verify that your OAuth2 token has the necessary scope (
https://www.googleapis.com/auth/youtube.readonlyor broader) to access video details including tags.Verify Video ID: Double-check that the video IDs you're querying (
data.id.videoId) are correct and belong to your channel.Review API Responses: Inspect the JSON responses from YouTube API to ensure that tags are indeed present in the
snippetpart of the video details.Test with Public Videos: Initially, test with videos that are public to ensure that your API integration and authentication flow are correctly implemented.
If you still face issues, it might help to log the raw API response (
tagResponse0.Content) to understand exactly what data is being returned and whether it includes thetagsfield for your videos. Adjustments can then be made based on the specific nature of the returned data.Ramco RamcoRank #462 · 5.4K reputationPosted Jun 19, 2024, 7:16 AM EDT
Hi Prasad
It is not showing my videos. I want my own videos list's search keyworrds
Thanks