Search code examples
pythongoogle-drive-apipydrive

Get shareable link of Google Drive files in a specific folder


I've been trying to apply the solution described here, adapting from the PyDrive documentation. What I want is to work on files in a specific folder, not get a list of all files in my Drive (which contains thousands). So I've tried:

files = drive.ListFile({'q': "'myfolder' in parents"}).GetList()

where myfolder is the name of the folder I want to get this list from. However, this returns an HTTP 404 error. Replacing myfolder with root works (per Google's example), but take ages (so my syntax is correct, but I probably misunderstand what parents represents).

Can anyone help?


Solution

  • I actually was nearly there: I needed to pass the folder ID instead of the name in the query:

    files = drive.ListFile({'q': "'folder_id' in parents"}).GetList()
    

    From there, I get a collection of dictionaries from which it's easy to get the file name (title key) and shareable link (alternateLink).