Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

236
Vistas
When making a list by query request in GMail via C#, what's the "source"?

Context: C#, JavaScript, ClearScript

I've written a plugin for my ClearScript-enabled JavaScript that connects to GMail. Everything's fine regarding OAuth2 etc. What's not working is a query against the inbox. If I request the inbox without a query, that gives me data, but I don't want millions of records.

attach(".\\Plugin_GMail.dll")
var tuple = Plugin_GMail.GoogleMail.Mail.Mail_Authenticate(REDACTED)
var service = Plugin_GMail.GoogleMail.Mail.Mail_CreateService(tuple.Item1, "mail")
var request = service.Users.Labels.List("me");
var labels = request.Execute().Labels;
var before = new Date(2022,11,31).valueOf();
var after = new Date(2022,0,1).valueOf();
var res = Plugin_GMail.GoogleMail.Mail.Messages_ListByQuery(service, "me", "before:$b after:$a".replace("$b",before).replace("$a",after),true)

The code for Messages_ListByQuery is

        public static string Messages_ListByQuery(GmailService service, string userId, string query, bool debug = false)
        {
            if (debug) Debugger.Launch();
            var msgList = new List<Message>();

            var result = new JSONResponse();

            var request = service.Users.Messages.List(userId);
            request.MaxResults = 500;
            request.Q = query;
            request.LabelIds = "INBOX";

            while (true)
            {
                try
                {                   
                    var msgs = request.Execute().Messages;
                    if (msgs.Count() == 0)
                    {
                        break;
                    }
                    msgList.AddRange(msgs);
                }
                catch (Exception e)
                {
                    result.Error = e.Message;
                    break;
                }
            }
            result.Cargo = msgList;
            return JsonConvert.SerializeObject(result);
        }

So the response after executing the query-based List is

{"Error":"Value cannot be null.\r\nParameter name: source","Cargo":[],"Crew":null}

I have been through the documentation and can't find anything about "source". And there's nothing in the Playground about "source" either. Where next?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Your code is telling it to just loop forever, getting the same page of results.

while (true)   // loop forever
        {
            try
            {                   
                var msgs = request.Execute().Messages;  // get first page of results
                if (msgs.Count() == 0)  
                {
                    break; // will never hit unless user has no messages. in their inbox at all.
                }
                msgList.AddRange(msgs);  // keeps adding first page of messages over and over.
            }
            catch (Exception e)
            {
                result.Error = e.Message;
                break;
            }
        }

The line

var msgs = request.Execute().Messages;

Is just going to say run the request and get me messages. Which will always return messages as your running the same request over and over.

The following line is just going to add the messages to your list.

msgList.AddRange(msgs);

So with the while true you are telling your app to just request the same 500 rows again and again forever.

You should instead look at using the next page token and getting the next page of results instead of the same results over and over.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda