pythongoogle-drive-apipydrive

How to download file from google drive folder?


I have a script that gets a list of files from google drive

from pydrive.drive import GoogleDrive

gauth = GoogleAuth()
gauth.LoadCredentialsFile("mycreds.txt")

gauth.LoadCredentialsFile("mycreds.txt")
if gauth.credentials is None:
    gauth.LocalWebserverAuth()
elif gauth.access_token_expired:
    gauth.Refresh()
else:
    gauth.Authorize()
gauth.SaveCredentialsFile("mycreds.txt")

gauth.LocalWebserverAuth()
drive = GoogleDrive(gauth)

folder = "1CNtWRS005fkX6vlZowZiXYITNGifXPKS"

file_list = drive.ListFile({'q': f"'{folder}' in parents"}).GetList()

for file in file_list:
    print(file['title'])

-> 1.txt

It receives data only from its disk, but I need the script to receive a list of files from a folder to which it has access - "available to me". I have a folder ID, but if I substitute it in the folder field, nothing happens


Solution

  • I think gdown could help you.

    pip install gdown

    Then could try something like this:

    import gdown
    
    id = "folderId..."
    gdown.download_folder(id=id, quiet=True, use_cookies=False)