简体   繁体   中英

Which nuget package contains the method GetSheetService()?

I want to know whether there is a nuget package that contains GetSheetService(), I can't find which is the right package, anyone know this? Has anyone used this method?

This are the packages that I had installed:

  <ItemGroup>
    <PackageReference Include="Google.Apis" Version="1.40.3" />
    <PackageReference Include="Google.Apis.Auth" Version="1.40.3" />
    <PackageReference Include="Google.Apis.Auth.Mvc" Version="1.40.3" />
    <PackageReference Include="Google.Apis.Sheets.v4" Version="1.40.3.1694" />
    <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="1.0.28" />
  </ItemGroup>

and this is the problem I have encountered: 在此处输入图片说明

this is the start of the cs file:

using System;
using System.IO;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
using Google.Apis.Sheets.v4;

The google .net client library does not have a method called get sheets service. I suspect you are copying this from someones code some places. The correct way to create a sheets service follows

/// <summary>
    /// This method get a valid service
    /// </summary>
    /// <param name="credential">Authecated user credentail</param>
    /// <returns>SheetsService used to make requests against the Sheets API</returns>
    private static SheetsService GetService(UserCredential credential)
    {
        try
        {
            if (credential == null)
                throw new ArgumentNullException("credential");

            // Create Sheets API service.
            return new SheetsService(new BaseClientService.Initializer()
            {
                HttpClientInitializer = credential,
                ApplicationName = "Sheets Oauth2 Authentication Sample"
            });
        }
        catch (Exception ex)
        {
            throw new Exception("Get Sheets service failed.", ex);
        }
    }
}

Code ripped from my google .net client Library sample project. Oauth2Authentication.cs)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM