3

I'm using the Google Gmail API in JavaScript and I want to retrieve a specific set of emails using the query parameter in the list request, the problem is that I cannot get the number of emails that satisfy the query like {from:test@test.com to:test@test.com}, only inbox total or by tags/labels, which I do not want.

The request Users.messages: list returns this:

"nextPageToken": "1234567890123",
"resultSizeEstimate": 116

The number of emails in the current page.

Unless I loop over all the pages, I can't know the total number of emails satisfying the query.

Sebastian Simon
  • 18,263
  • 7
  • 55
  • 75
Drakota
  • 337
  • 1
  • 4
  • 16
  • Unsure of the efficiency, but could you batchModify the message list with a unique label and then count by that label? – dbr Aug 15 '17 at 22:18
  • You can not get the total amount of results from a query without looping over all the pages, sadly. I usually display `var count = messages.length <= 100 ? messages.length : "100+";` to my users. – Tholle Aug 16 '17 at 08:43
  • 1
    That's so weird that Google does no provide the option to get the amount of results for a query, your solution does not apply with me, I was trying to do a pagination where you could see the last page. If I don't know the total amount of results, I can't know how many pages there is. – Drakota Aug 16 '17 at 13:24
  • @Drakota Yeah, it is pretty disappointing. It doesn't work all too well in the Gmail client either, so there is probably some performance reason for it. If you search for e.g. `from:me` in the Gmail client, you might get `10-50 of about 81`, and when you go to the next page you might get `51-100 of about 148`. – Tholle Aug 17 '17 at 12:18

0 Answers0