Skip to content

Instantly share code, notes, and snippets.

@cp-sumi-k
Last active June 27, 2023 04:50
Show Gist options
  • Save cp-sumi-k/be41fdc357d96411b5db29a6777f70b9 to your computer and use it in GitHub Desktop.
Save cp-sumi-k/be41fdc357d96411b5db29a6777f70b9 to your computer and use it in GitHub Desktop.
// create api context
ctx := context.Background()
// get bytes from base64 encoded google service accounts key
credBytes, err := b64.StdEncoding.DecodeString(os.Getenv("KEY_JSON_BASE64"))
if err != nil {
log.Error(err)
return
}
// authenticate and get configuration
config, err := google.JWTConfigFromJSON(credBytes, "https://www.googleapis.com/auth/spreadsheets")
if err != nil {
log.Error(err)
return
}
// create client with config and context
client := config.Client(ctx)
// create new service using client
srv, err := sheets.NewService(ctx, option.WithHTTPClient(client))
if err != nil {
log.Error(err)
return
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment