2016/10/26

Google Drive APIs Explorer - Listing Files

This post is about how to use query for filtering the file results and selector to specify which fields to include in a partial response.

Listing files in the root folder

Assuming I want to list all the files that are not trashed in the root folder and I want to see the filename, id, and mimeType in the output result. Here is how to for the query in Google Drive APIs Explorer.

Step 1 - Go to https://developers.google.com/drive/v3/reference/files/list.

Step 2 - Select user for the corpus field, enter 'root' in parents and trashed=false for the field for q, and enter files(name,id,mimeType) for the field for fields.


Step 3 - Left click on the blue AUTHORIZE AND EXECUTE button and a window similar to the below one will pop up. Left click on AUTHORIZE AND EXECUTE.


Step 4 - If all goes well, result similar to the one below will appear in no time. Note how the inputs for corpus, q and fields are included in the request.


Listing files in a sub-folder under root

Assuming I want to list all the files in a folder called temp.



Instead of using the name "temp" in the query, we need to put in the id for folder "temp".

Step 1 - Right click on temp and select "Get shareable link".


Step 2 - A shareable link will be created and the link is copied to clipboard automatically.


Step 3 - Past the link in a notepad or similar app., the part after "=" is the id of folder "temp".


Step 4 - Enter '0B7w6iqcKu4TlLW1uWWVsMFM3bXM' in parents in the field for q.


Step 5 - The result.

Note,

I was having a hard time trying to figure out what to enter for "q" and "fields" until I found the sample in "File listing made easy" by PyDrive. I think it will be very helpful if Google could give more examples on how to use its APIs.

References

File listing made easy
https://pythonhosted.org/PyDrive/filelist.html

Search for Files
https://developers.google.com/drive/v3/web/search-parameters

No comments:

Post a Comment