func Callback(w http.ResponseWriter, r *http.Request){
ctx := context.Background()
state := r.FormValue("state")
code := r.FormValue("code")
client := getClient(state, code)
srv, err := gmail.NewService(ctx, option.WithHTTPClient(client))
if err != nil {
log.Fatalf("Unable to retrieve Gmail client: %v", err)
}
user := "me"
result, err := srv.Users.Messages.List(user).Do()
// result, err := srv.Users.GetProfile(user).Do() // This part works
if err != nil {
log.Fatalf("Unable to retrieve labels: %v", err)
}
// fmt.Fprintf(w, "Labels: %s", result.EmailAddress) // This part works
snippet := result.Messages[0].Snippet
fmt.Fprint(w, string(snippet)) // For some reason give a blank output
}
Gmail API Go Client
Some parts like the snippet and the body do print out an output. But the profile and listing of labels works.
I'm not sure what I'm doing incorrectly :(