none
Is it possible to use Google Sheets API from an Azure Function? RRS feed

  • Question

  • I'm trying to write a Google Sheet from an C# Azure function using Google Sheets API. The problem may be silly but I don't seem to be able to find a way to add reference to it.

    Following documentation, I've set my function as:

    using Google.Apis.Auth.OAuth2;
    using Google.Apis.Sheets.v4;
    using Google.Apis.Sheets.v4.Data;
    using Google.Apis.Services;
    using Google.Apis.Util.Store;
    using System;
    using System.Collections.Generic;
    using System.IO;
    using System.Threading;
    
    public static void Run(TimerInfo myTimer, TraceWriter log)
    {
        log.Info($"C# Timer trigger function executed at: {DateTime.Now}");
    }

    I get errors on the 'using' lines for Google.Apis. What I get is:

    ...error CS0246: The type or namespace name 'Google' could not be found (are you missing a using directive or an assembly reference?)

    I understand I have to add a reference like #r "Google" at the very start, but I can't actually find which one exactly; I didn't even find if this is something possible to do.

    How should I set it up to work with Google Sheet API?

    Thursday, September 19, 2019 1:39 PM

Answers

  • If you use azure function v2, you need to upload a function.proj file to the function's folder to add the reference of your nuget package. And if you use azure function v1, please upload a project.json instead.

    Here is an example of function.proj in azure function v2(since you want to use Google.Apis.Sheets.v4, so I post the example of Google.Apis.Sheets.v4 for your reference, if you want to add some other package you can add .

    <Project Sdk="Microsoft.NET.Sdk">
        <PropertyGroup>
            <TargetFramework>netstandard2.0</TargetFramework>
        </PropertyGroup>
    
        <ItemGroup>
            <PackageReference Include="Google.Apis.Sheets.v4" Version="1.41.1.1713" />
        </ItemGroup>
    </Project>

    After create the function.proj, please upload it to the function's folder by following the steps below:

    1. Go into your function on Azure portal and click "View files" on the right of your page.

    2. Click "Upload" to upload your function.proj file, if you don't want to upload it, you can also click "Add" to add the function.proj file and edit it on portal.

    After that, please notice the Logs at the bottom of you page to see if the packages restored successfully. And then you can use google sheet api.

    For further information of how to use nuget package in azure function, please refer to this tutorial: https://docs.microsoft.com/en-us/azure/azure-functions/functions-reference-csharp#using-nuget-packages

    Friday, September 20, 2019 3:17 AM
    Moderator

All replies

  • If you use azure function v2, you need to upload a function.proj file to the function's folder to add the reference of your nuget package. And if you use azure function v1, please upload a project.json instead.

    Here is an example of function.proj in azure function v2(since you want to use Google.Apis.Sheets.v4, so I post the example of Google.Apis.Sheets.v4 for your reference, if you want to add some other package you can add .

    <Project Sdk="Microsoft.NET.Sdk">
        <PropertyGroup>
            <TargetFramework>netstandard2.0</TargetFramework>
        </PropertyGroup>
    
        <ItemGroup>
            <PackageReference Include="Google.Apis.Sheets.v4" Version="1.41.1.1713" />
        </ItemGroup>
    </Project>

    After create the function.proj, please upload it to the function's folder by following the steps below:

    1. Go into your function on Azure portal and click "View files" on the right of your page.

    2. Click "Upload" to upload your function.proj file, if you don't want to upload it, you can also click "Add" to add the function.proj file and edit it on portal.

    After that, please notice the Logs at the bottom of you page to see if the packages restored successfully. And then you can use google sheet api.

    For further information of how to use nuget package in azure function, please refer to this tutorial: https://docs.microsoft.com/en-us/azure/azure-functions/functions-reference-csharp#using-nuget-packages

    Friday, September 20, 2019 3:17 AM
    Moderator
  • Any updates on this ?
    Monday, September 23, 2019 3:21 AM
    Moderator
  • Thanks. That was answered here as well https://stackoverflow.com/questions/58011478/is-it-possible-to-use-google-sheets-api-from-an-azure-function

    I was able to do it by project.json file.

    Friday, September 27, 2019 5:20 PM