简体   繁体   中英

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

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM