not able to read a google group email with GMAIL api in golang

this is my code. service account has domain wide delegation and access to gmail.readonly 

 

 

// Read the service account credentials from the JSON file.
	credsJSON, err := ioutil.ReadFile(serviceAccountJSONFile)
	if err != nil {
		http.Error(w, "Failed to read service account credentials", http.StatusInternalServerError)
		log.Printf("Failed to read service account credentials from file: %v", err)
		return
	}

	// Load the service account credentials from the JSON data.
	creds, err := google.CredentialsFromJSON(ctx, credsJSON, gmail.GmailReadonlyScope)
	if err != nil {
		http.Error(w, "Failed to load service account credentials", http.StatusInternalServerError)
		log.Printf("Failed to load service account credentials: %v", err)
		return
	}

	// Create a new Gmail service using the service account's credentials.
	gmailService, err := gmail.NewService(ctx, option.WithCredentials(creds))
	if err != nil {
		http.Error(w, "Failed to create Gmail service", http.StatusInternalServerError)
		log.Printf("Failed to create Gmail service: %v", err)
		return
	}

	// Fetch the emails from the Google Group (replace with the actual Google Group email address).
	groupEmail := "testemail@xyz.com"
	messages, err := gmailService.Users.Messages.List(groupEmail).Q("is:inbox").MaxResults(10).Do()
	if err != nil {
		http.Error(w, "Failed to fetch emails", http.StatusInternalServerError)
		log.Printf("Failed to fetch emails: %v", err)
		return
	}

 

 

. I am not sure what I am doing wrong. I am getting this error

googleapi: Error 400: Precondition check failed., failedPrecondition
 

0 0 394
0 REPLIES 0
Top Solution Authors