How to get list of files by folder on Google Drive API
You should be able to simply use files/list with a parent query;
GET https://www.googleapis.com/drive/v2/files?q='BB0CHANGEDIDF5waGdzbUQ5aWs'+in+parents&key={YOUR_API_KEY}
How to get a list of entries for a directory in Google Drive?
In v2 there was the Children resource, which you could use to list a folder's children (there was also the Parents resource, which you could use to list a file's parents). Because this resources functionalities could be achieved with Files: list, they were dropped in v3.
So in v3, the way to list files in a folder is by using the search query, as you said, like q: 'your-folder-id' in parents
.
And if you want to include all files and folders inside subfolders, refer to the thread referenced by Tanaike.
Reference:
- Drive API v3 versus v2
Getting a list of files by folder on Drive SDK
NB This answer uses the v2 API. New applications should write to the v3 API.
It is now possible to use the drive.files.list endpoint to list files belonging to a specific folder.
To do so, you can use the ?q=
query parameter as follows:
GET https://www.googleapis.com/drive/v2/files?q="'<FOLDER_ID>' in parents"
In PHP, that would be
$service->files->list(array('q' => "'<FOLDER_ID>' in parents"));
How to get a list of all files in directory with Google Drive API(v3)
- You want to retrieve all files just under the root folder.
- You want to achieve this using google-api-go-client with golang.
- You have already been get and put values for Google Drive using Drive API.
If my understanding is correct, how about this answer? Please think of this as just one of several possible answers.
Issue and workaround:
From the situation of When I call this function, it return me files that only I added with my program (this program also can upload files to Google Drive), not all files.
, I thought that your scopes might include https://www.googleapis.com/auth/drive.file
. When https://www.googleapis.com/auth/drive.file
is used as the scope, only the files created by the application are retrieved.
In order to retrieve all files just under the root folder, please use the following scopes.
https://www.googleapis.com/auth/drive
https://www.googleapis.com/auth/drive.readonly
https://www.googleapis.com/auth/drive.metadata.readonly
https://www.googleapis.com/auth/drive.metadata
.
If you want to retrieve only the file list, the scopes of .readonly
can be used.
Modified script:
From your question, I could notice that you are using google-api-go-client with golang and Go Quickstart. In this case, how about the following modification?
If drive.DriveFileScope
is included in the scopes, please modify as follows.
config, err := google.ConfigFromJSON(b, drive.DriveFileScope)
To:config, err := google.ConfigFromJSON(b, drive.DriveMetadataScope)
or
config, err := google.ConfigFromJSON(b, drive.DriveReadonlyScope)
- If you want to also upload the file, please use
drive.DriveScope
.
Note:
- When you modified the scopes, please remove the file of
token.json
oftokFile := "token.json"
. And please run the script and authorize again. By this, the modified scopes are reflected to the access token and refresh token. Please be careful this.
References:
- google-api-go-client
- Go Quickstart
- Files: list
If I misunderstood your question and this was not the direction you want, I apologize.
List of files in a google drive folder with python
You can look here for an example of how to list files in Drive: https://developers.google.com/drive/api/v3/search-files . You need to construct a query that lists the files in a folder: use
q = "'1234' in parents"
where 1234 is the ID of the folder that you want to list. You can modify the query to list all the files of a particular type (such as all jpeg files in the folder), etc.
Google Drive API v3, is there anyway to list of files and folders from a root folder?
- You want to retrieve files and folders in the root folder using the search query.
If my understanding is correct, how about this answer?
Pattern 1:
You want to retrieve the folders in the root folder, you can use the following query.
mimeType = 'application/vnd.google-apps.folder' and 'root' in parents
- You can test this at Try this API.
Pattern 2:
You want to retrieve the files and folders in the root folder, you can use the following query.
'root' in parents
- You can test this at Try this API.
Note:
- With only the search query, all files and folders under the specific folder including the subfolders cannot be retrieved. In this case, it is required to prepare the script for retrieving them. Please be careful this.
References:
- Files: list
- Search for Files
If I misunderstood your question and this was not the direction you want, I apologize.
Golang - get list of files from a shared Google Drive folder
I believe your goal is as follows.
- You want to retrieve the file list from the shared drive using googleapis for go.
In this case, how about the following modification?
From:
r, err := driveService.Files.List().
DriveId('XXXXXXXXXX').
PageSize(10).
Fields("nextPageToken, files(id, name)").
Do()
To:
r, err := driveService.Files.List().
DriveId("XXXXXXXXXX").
Corpora("drive").
SupportsAllDrives(true).
IncludeItemsFromAllDrives(true).
PageSize(10).
Fields("nextPageToken, files(id, name)").
Do()
Note:
- In this modification, it supposes that you have permission for reading the shared drive and you have already been able to use Drive API. Please be careful about this.
Reference:
- Files: list
Related Topics
How to Check If Variable Is Array... or Something Array-Like
Connection Reset by Peer: Mod_Fcgid: Error Reading Data from Fastcgi Server
Get Date for Monday and Friday for the Current Week (Php)
Simple Comet Example Using PHP and Jquery
How to Remove Empty Paragraph Tags from String
In PHP How Does Usort() Function Works
PHP & MySQL: When Exactly to Use HTMLentities
PHP - How to Implement Password Reset and Token Expiry
PHP Datetime Microseconds Always Returns 0
How to Install an Older Version of PHPunit Through Pear
Php: Limit Foreach() Statement
Returning Header as Array Using Curl
How to Send Notification to Android from PHP
Adding Multiple Items to Woocommerce Cart at Once
Send Emails with International Accent and Special Characters
Php: Get List of All Filenames Contained Within My Images Directory