Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

234
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda