Google API client Library for .NET

repository·main·Indexed 23 days ago

https://github.com/googleapis/google-api-dotnet-client

A client library enabling .NET applications to access Google APIs such as Drive, YouTube, and Calendar using OAuth2.0 authentication. It provides strongly-typed, modular NuGet packages for specific services (e.g., Google.Apis.Sheets.v4) and supports .NET Framework 4.6.2+, .NET Standard 2.0, and .NET 6.0+. Note that this library is in maintenance mode and is distinct from the Cloud Client Libraries for .NET designed specifically for Google Cloud Platform services.

Tokens
14.3K
Snippets
3
Records
21
Agent score
81%

What's inside google-api-dotnet-client

  1. Overview of the Google API client Library for .NET

    main
    The Google API client library for .NET provides access to a wide range of Google APIs, including Drive, YouTube, Calendar, Storage, and Analytics. It supports OAuth2.0 authentication. The library uses strongly-typed per-API libraries generated via Google's Discovery API.
  2. Overview of Google.Apis.Auth.AspNetCore3

    main

    The Google.Apis.Auth.AspNetCore3 NuGet package provides a Google-specific OpenIdConnect authentication handler for ASP.NET Core 3 applications.

    Key features include:

    • Incremental Auth Support: Allows requesting additional scopes as needed.
    • Injectable Provider: Defines an IGoogleAuthProvider interface that can be injected into your services to supply Google credentials.
  3. Understand the maintenance mode status of the Google API .NET client library

    main

    The Google API .NET client library is currently in maintenance mode. This means:

    • Feature Set: The libraries are considered mature and complete. No major new features are expected to be added.
    • Support: The team continues to support the libraries by fixing bugs and adding minor features necessary to maintain compatibility with ongoing changes to the .NET platform.
    • API Updates: New versions of existing API libraries will be released as they become available, and new API libraries will be released as new Google services become available.
  4. Locate API-specific libraries and generated source code

    main
    API-specific libraries are produced by the gapic-generator-csharp. In this repository, you can find the most recently generated code in the Src/Generated/ directory and the discovery documents used for generation in the DiscoveryJson/ directory.
  5. Check platform support for the Google API .NET client library

    main

    The library does not officially support the following platforms:

    • Unity
    • Xamarin
    • UWP (Universal Windows Platform)

    Support for these platforms is not currently provided due to insufficient usage to justify the required technical work and infrastructure. The decision is reviewed periodically.

  6. Find and install API-specific NuGet packages

    main

    The Google APIs client library for .NET is modular. Instead of installing one massive library, you should install the specific NuGet package corresponding to the Google API you want to use. Each package follows the naming convention Google.Apis.[ServiceName].[Version].

    Commonly used API packages include:

    • Google Sheets API v4: Google.Apis.Sheets.v4
    • Cloud Storage JSON API v1: Google.Apis.Storage.v1
    • Cloud Spanner API v1: Google.Apis.Spanner.v1
    • Cloud Speech-to-Text API v1: Google.Apis.Speech.v1
    • Cloud Text-to-Speech API v1: Google.Apis.Texttospeech.v1

    You can find the exact package for your required service in the project's documentation or by searching NuGet for the service name.

  7. Implement Google.Apis.Auth.AspNetCore3 in your application

    main

    The integration test application demonstrates the standard implementation pattern for this library:

    • Configuration: Check Startup.cs to see how to register the Google-specific OpenIdConnect authentication handler.
    • Usage in Controllers: Check Controllers/HomeController.cs to see how to access credentials and perform authenticated actions.
    • Credential Loading: The sample uses a helper class ClientInfo.cs to load the OAuth client ID and secret from the client_secrets.json file. In production, you should use a secure method to store and retrieve these credentials.
  8. Run the Google.Apis.Auth.AspNetCore3 Integration Test App

    main

    You can run the sample application to see the library in action. This requires ASP.NET Core 3.1 or Visual Studio 2019.

    1. Clone the repository locally using Git.
    2. Navigate to the integration test directory: google-api-dotnet-client/Src/Support/Google.Apis.Auth.AspNetCore3.IntegrationTests
    3. Execute the application using the .NET CLI:
      dotnet run
    4. The local web server will start, and a browser should open to the Index page, where you can test various authentication features.
    dotnet run
  9. Install API-specific NuGet packages

    main
    The Google APIs client library for .NET is distributed via individual NuGet packages for each specific API. To use a particular Google service, you must install its corresponding NuGet package. For example, to use the Cloud Tasks API v2, you would install Google.Apis.CloudTasks.v2.