Reputation: 159
Google.Apis.Gmail.v1.UsersResource.MessagesResource.ListRequest has a property, MaxResults which is the "Maximum number of messages to return". The default value is 100. The following code allows me to change MaxResults:
var request = new UsersResource.MessagesResource.ListRequest(service, "me");
request.MaxResults = 5;
IList<Message> messages = request.Execute().Messages;
If I specify a value < 100, only that number of messages is returned. However, if I specify a number > 100 only 100 are returned. How can I have ALL messages returned?
Upvotes: 3
Views: 1034
Reputation: 112877
If you try out the API explorer for listing messages, you can see that if you get 100 or more results, Google will page it for you so that you don't end up accidentally fetching thousand of results. To get the next page, simply include the nextPageToken
you get from the first response in your next request:
Request:
GET https://www.googleapis.com/gmail/v1/users/me/messages
Response (Page 1):
{
"messages": [
{
"id": "15049b2405be054a",
"threadId": "15049b2405be054a"
}, . . .
],
"nextPageToken": "07838313978415221418"
}
Next request:
GET https://www.googleapis.com/gmail/v1/users/me/messages?pageToken=07838313978415221418
Response (Page 2):
{
"messages": [
{
"id": "14ffa7f009d50dd1",
"threadId": "14ffa7f009d50dd1"
}, ...
], ...
}
Just keep on doing this until there is no nextPageToken
in the response, and you will have fetched every result.
Upvotes: 2