0

I have a folder in my google drive and I want to list its files and subfolders using google drive Api through a search box. Does Api provide any flexibility to get folders.

I've a script to get folders but it's not working properly. Showing some trashed folder. I want files too.

   $this->client = $googl->client();
   $this->drive = $googl->drive($this->client);
   $folderId = '0B4JDg65OBlTM3RseUk';
   $parameters = [
            'q' => "'$folderId' in parents",
            'fields' => 'files(id, name, modifiedTime, iconLink, 
             webViewLink, webContentLink)'];
   $result = $this->drive->files->listFiles($parameters);
Muhammad
  • 339
  • 3
  • 22
  • What exactly isn't 'working properly'? Does it run? Does it crash? Does it produce errors, and if so what error? It's hard for people to help you if you don't describe WHAT is going wrong. – Teun van der Wijst Nov 29 '18 at 11:10
  • Well it's showing some folders that are in trashed. But I want to list all the files in folder. – Muhammad Nov 29 '18 at 11:15

1 Answers1

0

To list files, you may use the files.list method of the API. This method accepts the q parameter, which is a search query combining one or more search terms.

Response:

{
  "kind": "drive#fileList",
  "nextPageToken": string,
  "incompleteSearch": boolean,
  "files": [
    files Resource
  ]
}

Example for files.list:

Search for the ID 1234567 in the parents collection. This finds all files and folders located directly in the folder whose ID is 1234567.

'1234567' in parents

To see the valid search parameters, you may visit this link.

Jacque
  • 757
  • 4
  • 9
  • and how is this going to take folderid and give response as it childs – Muhammad Nov 30 '18 at 06:21
  • If you would click the second link, it will lead you to the page where you can see the valid `q` parameters and some examples. I have edited my answer to include the example for searching files and folders located in the specified folder ID. – Jacque Nov 30 '18 at 06:30
  • if there are sub folders than how I'm supposed to get the files from subfolder ? – Muhammad Nov 30 '18 at 06:39
  • Please refer to this [SO post](https://stackoverflow.com/questions/46545336/search-files-recursively-using-google-drive-rest/46562607#46562607). – Jacque Nov 30 '18 at 07:14