Hi
I want to get all Youtube Search Words of my Channel.
Thatns
Hi
I want to get all Youtube Search Words of my Channel.
Thatns
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Tahir AnsariRank #366 · 6.8K reputationPosted Oct 16, 2023, 3:21 AM EDT
reate a Google Cloud Project and Enable the YouTube Data API:
Generate API Credentials:
Install Google API Client Library for .NET: Use NuGet Package Manager in your C# project to install the "Google.Apis.YouTube.v3" library, which provides access to the YouTube Data API.
Write C# Code to Retrieve Search Terms: Use the following code snippet as a starting point to retrieve search terms for your channel. Replace
"YOUR_API_KEY"with your API key.using Google.Apis.Auth.OAuth2; using Google.Apis.Services; using Google.Apis.YouTube.v3; using System; class Program { static void Main() { string apiKey = "YOUR_API_KEY"; var youtubeService = new YouTubeService(new BaseClientService.Initializer() { ApiKey = apiKey, ApplicationName = "YourApp" }); var channelRequest = youtubeService.Channels.List("snippet"); channelRequest.Mine = true; var channelResponse = channelRequest.Execute(); if (channelResponse.Items.Count == 1) { var channelId = channelResponse.Items[0].Id; var searchListRequest = youtubeService.Search.List("snippet"); searchListRequest.ChannelId = channelId; searchListRequest.Type = "video"; searchListRequest.Order = SearchResource.ListRequest.Order.Date; var searchListResponse = searchListRequest.Execute(); foreach (var searchResult in searchListResponse.Items) { Console.WriteLine($"Search Term: {searchResult.Snippet.Title}"); } } else { Console.WriteLine("Channel not found or API key is incorrect."); } } }Amit MohantyRank #112 · 20K reputationPosted Oct 16, 2023, 7:06 AM EDT
class Program { static void Main() { string apiKey = "YOUR_API_KEY"; string channelId = "YOUR_CHANNEL_ID"; var client = new RestClient("https://www.googleapis.com/youtube/v3"); var request = new RestRequest("search", Method.GET); request.AddQueryParameter("key", apiKey); request.AddQueryParameter("channelId", channelId); request.AddQueryParameter("type", "video"); request.AddQueryParameter("part", "snippet"); request.AddQueryParameter("maxResults", "50"); // You can adjust this value IRestResponse response = client.Execute(request); if (response.IsSuccessful) { var responseData = Newtonsoft.Json.JsonConvert.DeserializeObject(response.Content); List searchTerms = new List(); foreach (var item in responseData.items) { searchTerms.Add(item.snippet.title); } foreach (var term in searchTerms) { Console.WriteLine(term); } } else { Console.WriteLine("Error: " + response.ErrorMessage); } } } public class SearchResponse { public List items { get; set; } } public class SearchItem { public SearchSnippet snippet { get; set; } } public class SearchSnippet { public string title { get; set; } }Naimish MakwanaRank #324 · 7.7K reputationPosted Oct 17, 2023, 7:11 AM EDT
Try below
using System; using System.Net.Http; using System.Threading.Tasks; class Program { static async Task Main(string[] args) { string apiKey = "YOUR_API_KEY"; // Replace with your actual API Key string channelId = "YOUR_CHANNEL_ID"; // Replace with your channel's ID using (HttpClient client = new HttpClient()) { // Set the base URL for the YouTube Data API client.BaseAddress = new Uri("https://www.googleapis.com/youtube/v3/"); // Make a GET request to retrieve channel sections HttpResponseMessage response = await client.GetAsync($"channels?key={apiKey}&part=snippet&id={channelId}"); if (response.IsSuccessStatusCode) { var channelData = await response.Content.ReadAsAsync(); if (channelData.Items.Count > 0) { var channel = channelData.Items[0]; // Get the default search section (usually the first one) var searchSection = channel.Snippet.DefaultSection; // Retrieve the search keywords var searchKeywords = searchSection.Metadata.Keywords; Console.WriteLine("Search Keywords: " + searchKeywords); } } else { Console.WriteLine("Failed to retrieve data. Status code: " + response.StatusCode); } } } } class ChannelResponse { public List Items { get; set; } } class Channel { public string Id { get; set; } public ChannelSnippet Snippet { get; set; } } class ChannelSnippet { public string DefaultSection { get; set; } }Thanks