Air University
Air University

Reputation: 85

how to open folder of google drive using google drive api in axios/javascript

I am trying to open the folder and see the files inside

const children = await axios.get(
      `https://www.googleapis.com/drive/v3/files/${folder.id}`,
      {
        params: {
          fields: "files(id, name)",
          spaces: "drive",
        },
        headers: {
          authorization: `Bearer ${accessToken}`,
        },
      }
    );

can we open sub folder using folder id? i tried it but it show errors

Upvotes: 1

Views: 507

Answers (2)

Syed Ali Shahzil
Syed Ali Shahzil

Reputation: 1224

As google drive doc uses q parameter to get a list of files inside a folder

q:"'{FolderID}' in parents"

so your Axios get request will be like that

const emptyFoldersSearch2 = await axios.get(
      "https://www.googleapis.com/drive/v3/files",
      {
        params: {
          q:"'1VwXsYxTTGid9GIYHzkzD7LPFN5bRUSKD' in parents" ,
        },
        headers: {
          authorization: `Bearer ${accessToken}`,
        },
      }
    );

Upvotes: 1

Linda Lawton - DaImTo
Linda Lawton - DaImTo

Reputation: 116948

Check the q pram search opperators with file.list it will let you list the files with in a folder

q=parents%20in%20%27root%27

Or

curl \
  'https://www.googleapis.com/drive/v3/files?q=parents%20in%20%27root%27&key=[YOUR_API_KEY]' \
  --header 'Authorization: Bearer [YOUR_ACCESS_TOKEN]' \
  --header 'Accept: application/json' \
  --compressed

Upvotes: 2

Related Questions