public List<string> links = new List<string>(); public List<string> titles = new List<string>(); public MainForm() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { this.Run().Wait(); for (int i = 0; i < titles.Count; i++) { listView1.Items.Add(titles[i]).SubItems.Add(links[i]); } } private async Task Run() { var youtubeService = new YouTubeService(new BaseClientService.Initializer() { ApiKey = "myAPIKey", ApplicationName = this.GetType().ToString() }); var searchListRequest = youtubeService.Search.List("snippet"); searchListRequest.Q = "Michael Jackson"; searchListRequest.MaxResults = 50; searchListRequest.VideoCategoryId = "10"; searchListRequest.Type = "video"; var searchListResponse = await searchListRequest.ExecuteAsync(); foreach (var searchResult in searchListResponse.Items) { switch (searchResult.Id.Kind) { case "youtube#video": titles.Add(searchResult.Snippet.Title); links.Add("https://www.youtube.com/watch?v=" + searchResult.Id.VideoId); break; } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)