javascriptaxiosgoogle-apigoogle-drive-apifetch-api

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


Solution

  • 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}`,
            },
          }
        );