Iwark / spreadsheet

Google Go (golang) library for reading and writing spreadsheet files on Google Docs.
MIT License
382 stars 53 forks source link

Will this only work with service accounts? #14

Closed Sjeanpierre closed 7 years ago

Sjeanpierre commented 7 years ago

I am writing a project that uses google.golang.org/api/drive/v3 and also this library. The drive library expects client auth credentials but this project seems to expect a service account. is there a way to use a unified set of credentials for both?

Sjeanpierre commented 7 years ago

Sorry found how to pass the client using the same stuff used in the google api

func newSheetClient() *spreadsheet.Service{
    client := googleClient()
    srv := spreadsheet.NewServiceWithClient(client)
    return srv
}

func googleClient() *http.Client{
    ctx := context.Background()

    b, err := ioutil.ReadFile("client_secret.json")
    if err != nil {
        log.Fatalf("Unable to read client secret file: %v", err)
    }

    config, err := google.ConfigFromJSON(b, SCOPES...)
    if err != nil {
        log.Fatalf("Unable to parse client secret file to config: %v", err)
    }
    client := getClient(ctx, config)
    return client
}