0
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 :(

  • 1
    Hi, can you please clarify your desired output as well as what error message if any, you are getting? Anyway, Have you seen this documentation about [Gmail API:Go Quickstart](https://developers.google.com/gmail/api/quickstart/go)? – Twilight Nov 12 '22 at 01:21

0 Answers0