When you query the Tasks Object for all of the Tasks each "Page" will contain the maxResults number of Results (default maxResults=100). If you have over 100 Tasks in a Specific TaskList or want to use pagination, you need to use pageToken to request subsequent "pages" of Tasks.
This can be done by running list() (TasksCollection Class), then retrieving the nextPageToken(). Subsequently running list() and passing in the nextPageToken, as an optional argument will give you the 2nd page of results.
var tasksObj = Tasks.Tasks.list(MytaskListId, {maxResults : 20});
var nextPageToken = tasksObj.getNextPageToken();
tasksObj = Tasks.Tasks.list(MytaskListId, {maxResults : 20, pageToken: nextPageToken});
var tasks = tasksObj.getItems();
//"tasks" will hold the Tasks 20 to 40.
However, I am confused by why the documentation shows a setNextPageToken method https://developers.google.com/apps-script/class_tasks_v1_schema_tasks#setNextPageToken What can that be used for? The below code does not work because subsequent calls to list() without the nextPageToken argument will return the first set (i.e. items 1 to 20).
var tasksObj = Tasks.Tasks.list(MytaskListId, {maxResults : 20});
var nextPageToken = tasksObj.getNextPageToken();
tasksObj.setNextPageToken(nextPageToken);
tasksObj = Tasks.Tasks.list(MytaskListId, {maxResults : 20});
var tasks = tasksObj.getItems();
//"tasks" will hold the Tasks 1 to 20.
Am I missing something....what is the purpose of the setNextPageToken() method? Thanks.