Last active
June 27, 2023 04:50
-
-
Save cp-sumi-k/be41fdc357d96411b5db29a6777f70b9 to your computer and use it in GitHub Desktop.
https://blog.canopas.com/golang-interacting-with-google-spreadsheets-b381f819c2eb - spreadsheet-auth
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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