From 1e857bea59cda006d1b69f8784cc7c217aabc8d2 Mon Sep 17 00:00:00 2001 From: Steve Bazyl Date: Wed, 13 Dec 2023 09:44:27 -0700 Subject: [PATCH] Fix paging examples to continue on empty page. Should stop only when next page token is not provided. --- advanced/drive.gs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/advanced/drive.gs b/advanced/drive.gs index a0ff1ab18..80d819fec 100644 --- a/advanced/drive.gs +++ b/advanced/drive.gs @@ -52,20 +52,20 @@ function listRootFolders() { pageSize: 100, pageToken: pageToken }); + pageToken = folders.nextPageToken; if (!folders.files || folders.files.length === 0) { - console.log('All folders found.'); - return; + continue; } for (let i = 0; i < folders.files.length; i++) { const folder = folders.files[i]; console.log('%s (ID: %s)', folder.name, folder.id); } - pageToken = folders.nextPageToken; } catch (err) { // TODO (developer) - Handle exception console.log('Failed with error %s', err.message); } } while (pageToken); + console.log('All folders found.'); } // [END drive_list_root_folders] @@ -109,9 +109,9 @@ function listRevisions(fileId) { revisions = Drive.Revisions.list( fileId, {'fields': 'revisions(modifiedTime,size),nextPageToken'}); + pageToken = revisions.nextPageToken; if (!revisions.revisions || revisions.revisions.length === 0) { - console.log('All revisions found.'); - return; + continue; } for (let i = 0; i < revisions.revisions.length; i++) { const revision = revisions.revisions[i]; @@ -119,12 +119,12 @@ function listRevisions(fileId) { console.log('Date: %s, File size (bytes): %s', date.toLocaleString(), revision.size); } - pageToken = revisions.nextPageToken; } catch (err) { // TODO (developer) - Handle exception console.log('Failed with error %s', err.message); } } while (pageToken); + console.log('All revisions found.'); } // [END drive_list_revisions]