title: Using Google Apis from Azure Functions
body: <p>I'm trying to access Google Apis using Azure functions. The goal is to connect to load the contents of multiple Google Sheets into an Azure SQL database. I've been looking at the sample code <a href="https://developers.google.com/api-client-library/dotnet/guide/aaa_oauth#web-applications-aspnet-mvc" rel="nofollow noreferrer">here</a> but I can't figure out how to make it work using Azure Functions.</p>
  <p>When I create an AppFlowMetadata.csx file and use reference it in my run.csx using '#load &quot;AppFlowMetadata.csx&quot;', I get multiple compile errors:</p>
  <blockquote>
  <p>error CS0234: The type or namespace name 'Mvc' does not exist in the namespace 'System.Web' (are you missing an assembly reference?)</p>
  <p>error CS0234: The type or namespace name 'Mvc' does not exist in the namespace 'Google.Apis.Auth.OAuth2' (are you missing an assembly reference?)</p>
  <p>error CS0246: The type or namespace name 'FlowMetadata' could not be found (are you missing a using directive or an assembly reference?)</p>
  <p>error CS0246: The type or namespace name 'Controller' could not be found (are you missing a using directive or an assembly reference?)</p>
  <p>error CS0115: 'AppFlowMetadata.GetUserId(Controller)': no suitable method found to override</p>
  <p>error CS0115: 'AppFlowMetadata.Flow': no suitable method found to override</p>
  </blockquote>
  <p>AppFlwMetadata.csx:</p>
  <pre><code>using System;
  using System.Web.Mvc;
  
  using Google.Apis.Auth.OAuth2;
  using Google.Apis.Auth.OAuth2.Flows;
  using Google.Apis.Auth.OAuth2.Mvc;
  using Google.Apis.Drive.v3;
  using Google.Apis.Util.Store;
  
  public class AppFlowMetadata : FlowMetadata
  {
  private static readonly IAuthorizationCodeFlow flow =
      new GoogleAuthorizationCodeFlow(new GoogleAuthorizationCodeFlow.Initializer
          {
              ClientSecrets = new ClientSecrets
              {
                  ClientId = &quot;PUT_CLIENT_ID_HERE&quot;,
                  ClientSecret = &quot;PUT_CLIENT_SECRET_HERE&quot;
              },
              Scopes = new[] { DriveService.Scope.Drive },
              DataStore = new FileDataStore(&quot;Drive.Api.Auth.Store&quot;)
          });
  
  public override string GetUserId(Controller controller)
  {
      // In this sample we use the session to store the user identifiers.
      // That's not the best practice, because you should have a logic to identify
      // a user. You might want to use &quot;OpenID Connect&quot;.
      // You can read more about the protocol in the following link:
      // https://developers.google.com/accounts/docs/OAuth2Login.
      var user = controller.Session[&quot;user&quot;];
      if (user == null)
      {
          user = Guid.NewGuid();
          controller.Session[&quot;user&quot;] = user;
      }
      return user.ToString();
  
  }
  
  public override IAuthorizationCodeFlow Flow
  {
      get { return flow; }
  }
  }
  </code></pre>
  <p>project.json:</p>
  <pre><code>{
  &quot;frameworks&quot;: {
  &quot;net46&quot;:{
    &quot;dependencies&quot;: {
      &quot;Google.Apis.Drive.v3&quot;: &quot;1.25.0.834&quot;,
      &quot;Google.Apis.Sheets.v4&quot;: &quot;1.25.0.841&quot;,
      &quot;Google.Apis.Auth&quot;:&quot;1.25.0&quot;
    }
  }
  }
  }
  </code></pre>
  <p>Has anyone successfully used Azure functions to authenticate with Google Apis? Any guidance on how to apply the Google example to Azure?</p>