title: How to get OAuth AccessToken (google) for posting a job to Google Hire in C#?
body: <p>I'm trying to post a job at Google Hire. Prerequsites are done as metioned <a href="https://developers.google.com/search/apis/indexing-api/v3/prereqs" rel="nofollow noreferrer">here</a> . I got the service account credentials in a json file.</p>
  
  <p>I tried to get Access Token using :</p>
  
  <pre><code>var jsonFilePath = HttpContext.Current.Server.MapPath("~/GoogleKey/client_secret.json");
  
  
  var token = GetAccessTokenFromJSONKey(path,"https://www.googleapis.com/auth/indexing"); 
  
  public static async Task&lt;string&gt; GetAccessTokenFromJSONKeyAsync(string jsonKeyFilePath, params string[] scopes)
          {
              using (var stream = new FileStream(jsonKeyFilePath, FileMode.Open, FileAccess.Read))
              {
                  return await GoogleCredential
                      .FromStream(stream) // Loads key file  
                      .CreateScoped(scopes) // Gathers scopes requested  
                      .UnderlyingCredential // Gets the credentials  
                      .GetAccessTokenForRequestAsync(); // Gets the Access Token  
              }
  
          }
  
  
   public static string GetAccessTokenFromJSONKey(string jsonKeyFilePath, params string[] scopes)
          {
              return GetAccessTokenFromJSONKeyAsync(jsonKeyFilePath, scopes).Result;
          }
  </code></pre>
  
  <p>but the problem is after executing the function, it just hangs up/ stops responding. I'm unable to get any value in "token " .</p>
  
  <p>May I know as to where am I doing wrong ???</p>
  
  <p>Thanks in advance.</p>