Search code examples
node.jsgoogle-apigoogle-drive-api

email address missing from permissions list using google drive api


I am using google drive to give drive folder permissions. I am able to create permission for the shared drive using google drive API but when I get the list i don't get permission email address

const drive = google.drive({ version: 'v3', auth: oauth2Client });
await drive.permissions.create({
          fileId: franchiseFolderId,
          supportsAllDrives: true,
          requestBody: {
            type: 'user',
            role: 'writer',
            emailAddress: userEmail,
          },
        });
const permissions = await drive.permissions.list({
          fileId: folderId,
          supportsAllDrives: true,
        });
console.log('permissions', permissions.data.permissions);

from above permissions console i only get this information

[{
id: 'XXXXXXXXXXXXXXXXXXX',
type: 'user',
kind: 'drive#permission',
role: 'writer'
  }]

email address is there in typescript type file but not in the response. i am using google oauth 2 for authorization and i have one scope added when generating tokens

https://www.googleapis.com/auth/drive

Solution

  • In the case of "Permissions: list" of Drive API v3, it seems that the email address is not returned as the default value. So, in your showing script, how about using fields property as follows?

    From:

    const permissions = await drive.permissions.list({
              fileId: folderId,
              supportsAllDrives: true,
            });
    

    To:

    const permissions = await drive.permissions.list({
              fileId: folderId,
              supportsAllDrives: true,
              fields: "*", // <--- Added
            });
    

    Note:

    • If you want to retrieve only permission IDs and email addresses, you can also use the value of fields as follows.

        fields: "permissions(id,emailAddress),nextPageToken",
      

    Reference:

    • [Permissions: list of Drive API v3](Permissions: list)