79452532

Date: 2025-02-19 19:20:17
Score: 1.5
Natty:
Report link

thanks for the update. I actually did stumble upon this fix awhile back but forgot to post the answer here. Thx

const drive = google.drive({ version: "v3", auth });
let nextPageToken = null;
driveObject.members = [];

/// The permissions.list api behaves differently from other google drive apis (like drive.list) in that it will not
/// take a nextPageToken null param on the first call. It results in 'invalid token error'.
do {
    /// SET permParams BASED ON nextPageToken value. WORK-AROUND TO LIMITATION IN permissions.list API (see above)///
    if (nextPageToken == null) {
        permParams = {
            fileId: gdrive.id,
            pageSize: 100,
            supportsAllDrives: true,
            fields: "nextPageToken, permissions(id,emailAddress,role,photoLink)",
            useDomainAdminAccess: true
        }
    } else {
        permParams = {
            fileId: gdrive.id,
            pageToken: nextPageToken,
            pageSize: 100,
            supportsAllDrives: true,
            fields: "nextPageToken, permissions(id,emailAddress,role,photoLink)",
            useDomainAdminAccess: true
        }
    }
    const permissionList = await drive.permissions.list(permParams);
    nextPageToken = permissionList.data.nextPageToken;
Reasons:
  • Blacklisted phrase (0.5): thanks
  • Blacklisted phrase (1): Thx
  • Long answer (-1):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: m365ken