Search code examples
javascriptaxiosgoogle-apigoogle-drive-api

why google drive does not return metadata of files which i provided in the fields parameter?


I am trying to get the Size of files with google drive API

const filesFilteredByDate = await axios.get('https://www.googleapis.com/drive/v3/files', {
   q: `mimeType = 'application/vnd.google-apps.folder'`,
    fields: 'files(id, name, size, modifiedTime)',
    orderBy: 'modifiedTime desc',
    spaces: 'drive',
    headers: {
      authorization: `Bearer ${accessToken}`
    }
  });

But it does not return the size and modified time of the folder enter image description here

So how do i get size , modifiedTime and createdTime


Solution

  • Size of the folder is not provided by google drive api more id, name,kind,mimeType are the default data object

    Moreover, put your fields inside params if you are using Axios just like that

    const filesFilteredByDate = await axios.get('https://www.googleapis.com/drive/v3/files', {
                params: {
                    q: "mimeType='application/vnd.google-apps.folder'",
                    fields: "files(id,name,createdTime,modifiedTime,parents)",
                    orderBy: "modifiedTime desc",
                },
                headers: {
                authorization: `Bearer ${accessToken}`
                }
            });