natinusala
natinusala

Reputation: 616

resultSizeEstimate is completely wrong

I've got a problem with the Gmail API and the resultSizeEstimate field of the messages.list method.

The value is completely wrong : if I query all of the messages of INBOX using https://www.googleapis.com/gmail/v1/users/me/messages?labelIds=INBOX, I got a resultSizeEstimate of 51, even if I can fetch more than 51 messages at once with maxResults.

The thing is that I've got more than 8k messages in my inbox, if I look in the Gmail GUI or using the labels.get.messagesTotal field.

That's not a problem if I want to have the total number of messages in a label since labels.get works fine, but how can I do to have the total number of messages of a specific query ? If I add a &q=... to my messages.list request, I still have a value of max results around 50, which is obviously wrong.

Thanks !

Upvotes: 1

Views: 566

Answers (1)

Tholle
Tholle

Reputation: 112857

resultSizeEstimate is just that, an estimate. You should probably not use it if it has to be a very close estimate.

You can't get the total amount of results of a query. You have to list until there is no nextPageToken in the response. Then you know you have gotten every result of the query.

Upvotes: 2

Related Questions