...

Text file src/google.golang.org/api/README.md

Documentation: google.golang.org/api

     1# Google APIs Client Library for Go
     2
     3## Getting Started
     4
     5```shell
     6$ go get google.golang.org/api/tasks/v1
     7$ go get google.golang.org/api/moderator/v1
     8$ go get google.golang.org/api/urlshortener/v1
     9... etc ...
    10```
    11
    12and using:
    13
    14```go
    15package main
    16
    17import (
    18        "context"
    19        "net/http"
    20
    21        "google.golang.org/api/urlshortener/v1"
    22)
    23
    24func main() {
    25        ctx := context.Background()
    26        svc, err := urlshortener.NewService(ctx)
    27        // ...
    28}
    29```
    30
    31* For a longer tutorial, see the [Getting Started guide](https://github.com/google/google-api-go-client/blob/main/GettingStarted.md).
    32* For examples, see the [examples directory](https://github.com/google/google-api-go-client/tree/main/examples).
    33* For support, use the [golang-nuts](https://groups.google.com/group/golang-nuts) mailing list.
    34
    35## Status
    36
    37[![Go Reference](https://pkg.go.dev/badge/google.golang.org/api.svg)](https://pkg.go.dev/google.golang.org/api)
    38
    39These are auto-generated Go libraries from the Google Discovery Service's JSON description files.
    40
    41Due to the auto-generated nature of this collection of libraries they may contain breaking changes from one release to
    42the next. The generator itself and the code it produces are considered beta for this reason.
    43
    44These client libraries are officially supported by Google.  However, the libraries are considered complete and are in
    45maintenance mode. This means that we will address critical bugs and security issues but will not add any new features.
    46
    47If you're working with Google Cloud Platform APIs such as Datastore or Pub/Sub, please use the
    48[Cloud Client Libraries for Go](https://github.com/googleapis/google-cloud-go) instead. These are the new and idiomatic
    49Go libraries targeted specifically at Google Cloud Platform Services.
    50
    51## Authorization
    52
    53By default, each API will use [Google Application Default Credentials](https://developers.google.com/identity/protocols/application-default-credentials)
    54for authorization credentials used in calling the API endpoints. This will allow your application to run in many
    55environments without requiring explicit configuration.
    56
    57```go
    58// import "google.golang.org/api/sheets/v4"
    59client, err := sheets.NewService(ctx)
    60```
    61
    62To authorize using a [JSON key file](https://cloud.google.com/iam/docs/managing-service-account-keys), pass
    63[`option.WithCredentialsFile`](https://pkg.go.dev/google.golang.org/api/option#WithCredentialsFile) to the `NewService`
    64function of the desired package. For example:
    65
    66```go
    67client, err := sheets.NewService(ctx, option.WithCredentialsFile("path/to/keyfile.json"))
    68```
    69
    70You can exert more control over authorization by using the [`golang.org/x/oauth2`](https://pkg.go.dev/golang.org/x/oauth2)
    71package to create an `oauth2.TokenSource`. Then pass [`option.WithTokenSource`](https://pkg.go.dev/google.golang.org/api/option#WithTokenSource)
    72to the `NewService` function:
    73
    74```go
    75tokenSource := ...
    76svc, err := sheets.NewService(ctx, option.WithTokenSource(tokenSource))
    77```
    78
    79## More information
    80
    81For some more information related to all of the generated clients please read through our
    82[package documentation](https://pkg.go.dev/google.golang.org/api#section-documentation).

View as plain text