February 2019
Intermediate to advanced
450 pages
11h 59m
English
Next, we need to set up the client from the credentials file that has been saved (in the current directory). We add a new function to parse the data, set up the authentication, and configure *gmail.Service using the following code:
func setupService() *gmail.Service { b, err := ioutil.ReadFile("credentials.json") if err != nil { log.Fatalf("Unable to read client secret file: %v", err) } config, err := google.ConfigFromJSON(b, gmail.GmailReadonlyScope, gmail.GmailComposeScope) if err != nil { log.Fatalf("Unable to parse client secret file to config: %v", err) } client := getClient(config) srv, err := gmail.New(client) if err != nil { log.Fatalf("Unable to retrieve Gmail client: %v", err) } return srv}
The service ...
Read now
Unlock full access