title: How do I make youtube api call to get categories according to given region and api key?
body: <p>I added this class to form1:</p>
  
  <pre><code>public class YoutubeApiResponse
          {
              public string kind { get; set; }
              public string etag { get; set; }
              public string nextPageToken { get; set; }
              public PageInfo pageInfo { get; set; }
              public List&lt;Item&gt; items { get; set; }
          }
  </code></pre>
  
  <p>The var Item not exist in the List</p>
  
  <p>Then in form1 constructor I did:</p>
  
  <pre><code>using (var client = new HttpClient())
              {
                  client.BaseAddress = new Uri("https://www.googleapis.com/youtube/v3/");
                  client.DefaultRequestHeaders.Accept.Clear();
                  client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
  
                  HttpResponseMessage response = client.GetAsync("search?q=manam&amp;type=video&amp;order=relevance&amp;part=snippet&amp;maxResults=50&amp;key=AIzaSyA4GZFAgfvsAItwFRmnAZvbTHoDeyunf2k").Result;
                  if (response.IsSuccessStatusCode)
                  {
                      var youtubeResponse = await response.Content.ReadAsAsync &lt; YoutubeApiResponse().Result();
                  }
              }
  </code></pre>
  
  <p>The api key is not valid api key, I just changed some letters random.</p>
  
  <p>And in this part i'm getting error on the line:</p>
  
  <pre><code>var youtubeResponse = await response.Content.ReadAsAsync &lt; YoutubeApiResponse().Result();
  </code></pre>
  
  <p>YoutubeApiResponse not exist so I changed it to YoutubeApiResponse but this doesn't have the Result property.</p>
  
  <p>Another error on this line: Error   2   The 'await' operator can only be used within an async method. Consider marking this method with the 'async' modifier and changing its return type to 'Task'.    </p>
  
  <p>And:</p>
  
  <p>Error   1   'System.Net.Http.HttpContent' does not contain a definition for 'ReadAsAsync' and no extension method 'ReadAsAsync' accepting a first argument of type 'System.Net.Http.HttpContent' could be found (are you missing a using directive or an assembly reference?)</p>
  
  <p>And the link that I'm using should be used to get the categories according to given region is: <a href="https://www.googleapis.com/youtube/v3/videoCategories?part=snippet&amp;regionCode=IL&amp;key=AIzaSyBgc1Gx-0tHbWp6-SWE0sQarpc6nGLtttt" rel="nofollow">https://www.googleapis.com/youtube/v3/videoCategories?part=snippet&amp;regionCode=IL&amp;key=AIzaSyBgc1Gx-0tHbWp6-SWE0sQarpc6nGLtttt</a></p>
  
  <p>In this example region code IL and api key.</p>
  
  <p>I just not sure how to use it in my c# code.
  This is my form1 code:</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.ComponentModel;
  using System.Data;
  using System.Drawing;
  using System.Linq;
  using System.Text;
  using System.Threading.Tasks;
  using System.Windows.Forms;
  using System.IO;
  using System.Reflection;
  using System.Threading;
  using System.Net.Http;
  using System.Net.Http.Headers;
  
  using Google.Apis.Auth.OAuth2;
  using Google.Apis.Services;
  using Google.Apis.Upload;
  using Google.Apis.Util.Store;
  using Google.Apis.YouTube.v3;
  using Google.Apis.YouTube.v3.Data;
  
  using Google.GData.Client;
  using Google.GData.Extensions;
  using Google.GData.Extensions.MediaRss;
  
  namespace Youtube_Manager
  {
  
      public partial class Form1 : Form
      {
          List&lt;string&gt; results = new List&lt;string&gt;();
          string err1 = ""
          string userName = "someone@gmail.com";
  
          public Form1()
          {
              InitializeComponent();
  
  
              using (var client = new HttpClient())
              {
                  client.BaseAddress = new Uri("https://www.googleapis.com/youtube/v3/");
                  client.DefaultRequestHeaders.Accept.Clear();
                  client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
  
                  HttpResponseMessage response = client.GetAsync("search?q=manam&amp;type=video&amp;order=relevance&amp;part=snippet&amp;maxResults=50&amp;key=AIzaSyA4GZFAgfvsAItwFRmnAZvbTHoDeyunf2k").Result;
                  if (response.IsSuccessStatusCode)
                  {
                      var youtubeResponse = await response.Content.ReadAsAsync &lt; YoutubeApiResponse().Result();
                  }
              }
  
              UserCredential credential;
              using (FileStream stream = new FileStream(@"D:\C-Sharp\Youtube-Manager\Youtube-Manager\Youtube-Manager\bin\Debug\client_secrets.json", FileMode.Open, FileAccess.Read))
              {
                  credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
                      GoogleClientSecrets.Load(stream).Secrets,
                      new[] { YouTubeService.Scope.Youtube, YouTubeService.Scope.YoutubeUpload },
                      "user",
                      CancellationToken.None,
                      new FileDataStore("YouTube.Auth.Store")).Result;
              }
              var youtubeService = new YouTubeService(new BaseClientService.Initializer()
              {
                  HttpClientInitializer = credential,
                  ApplicationName = Assembly.GetExecutingAssembly().GetName().Name
              });
              var video = new Video();
              video.Snippet = new VideoSnippet();
              video.Snippet.Title = "Default Video Title";
              video.Snippet.Description = "Default Video Description";
              video.Snippet.Tags = new string[] { "tag1", "tag2" };
              video.Snippet.CategoryId = "22";
              video.Status = new VideoStatus();
              video.Status.PrivacyStatus = "public";
              var filePath = @"C:\Users\bout0_000\Videos\test.mp4";//@"E:\video.mp4"; 
              using (var fileStream = new FileStream(filePath, FileMode.Open))
              {
  
                  const int KB = 0x400;
                  var minimumChunkSize = 256 * KB;
  
                  var videosInsertRequest = youtubeService.Videos.Insert(video,
                      "snippet,status", fileStream, "video/*");
                  videosInsertRequest.ProgressChanged +=
                      videosInsertRequest_ProgressChanged;
                  videosInsertRequest.ResponseReceived +=
                      videosInsertRequest_ResponseReceived;
                  // The default chunk size is 10MB, here will use 1MB.
                  videosInsertRequest.ChunkSize = minimumChunkSize * 4;
                  videosInsertRequest.Upload();
              }
          }
  
          private static void videosInsertRequest_ResponseReceived(Video obj)
          {
  
          }
  
          private static void videosInsertRequest_ProgressChanged(IUploadProgress obj)
          {
  
          }
  
          private async Task Run()
          {
              UserCredential credential = null;
              using (var stream = new FileStream(@"D:\C-Sharp\Youtube-Manager\Youtube-Manager\Youtube-Manager\bin\Debug\client_secrets.json", FileMode.Open, FileAccess.Read))
              {
                  try
                  {
                      credential = await GoogleWebAuthorizationBroker.AuthorizeAsync(
                          GoogleClientSecrets.Load(stream).Secrets,
                          // This OAuth 2.0 access scope allows for read-only access to the authenticated 
                          // user's account, but not other types of account access.
                          new[] { YouTubeService.Scope.YoutubeReadonly },
                          "user",
                          CancellationToken.None,
                          new FileDataStore(this.GetType().ToString())
                      );
                  }
                  catch (Exception errrr)
                  {
                      err1 = errrr.ToString();
                  }
              }
  
              var youtubeService = new YouTubeService(new BaseClientService.Initializer()
              {
                  HttpClientInitializer = credential,
                  ApplicationName = this.GetType().ToString()
              });
  
              var channelsListRequest = youtubeService.Channels.List("snippet,contentDetails");
              channelsListRequest.ForUsername = userName;
              var channelsListResponse = await channelsListRequest.ExecuteAsync();
  
              foreach (var channel in channelsListResponse.Items)
              {
                  var uploadsListId = channel.ContentDetails.RelatedPlaylists.Uploads;
                  var nextPageToken = "";
                  while (nextPageToken != null)
                  {
                      var playlistRequest = youtubeService.Playlists.List("id,snippet,contentDetails,status,player");
                      playlistRequest.Id = uploadsListId;
                      playlistRequest.MaxResults = 50;
                      playlistRequest.PageToken = nextPageToken;
                      var playlistListResponse = await playlistRequest.ExecuteAsync();
                      if (playlistListResponse.Items.Count &gt; 0)
                          MessageBox.Show(playlistListResponse.Items[0].Snippet.Title);
  
                  }
              }
          }
  
          private void Form1_Load(object sender, EventArgs e)
          {
  
          }
  
          public class YoutubeApiResponse
          {
              public string kind { get; set; }
              public string etag { get; set; }
              public string nextPageToken { get; set; }
              public PageInfo pageInfo { get; set; }
              public List&lt;Item&gt; items { get; set; }
          }
      }
  }
  </code></pre>
  
  <p>Using the part to get the categories according to given region id and add the categories later to a ComboBox as items that's i don't understand how to do.</p>