However, the check is overly-simplistic, so you might want to improve it or remove it. The part elif not itemType.startswith('application/'): has the purpose of skipping any Drive-format documents. I expect you to already have the ID of the folder that you want to download.
I've tried to keep it to-the-point, omitting code that's described in tutorials already. Here's just the code that deals specifically with downloading a folder recursively. If not os.path.isdir(bfolderpath + item):ĭownloadfiles(service, item, item, filepath) PageSize=1000, q=Folder_id+" in parents", fields="nextPageToken, files(id, name, mimeType)").execute() Service = build('drive', 'v3', credentials=creds)įolder_id = "'PAST YOUR SHARED FOLDER ID'" # Enter The Downloadable folder ID From Shared Link With open('token.pickle', 'wb') as token:
'credentials.json', SCOPES) # credentials.json download from drive API If creds and creds.expired and creds.refresh_token:įlow = om_client_secrets_file( # If there are no (valid) credentials available, let the user log in. With open('token.pickle', 'rb') as token: # created automatically when the authorization flow completes for the first # The file token.pickle stores the user's access and refresh tokens, and is Prints the names and ids of the first 10 files the user has access to. """Shows basic usage of the Drive v3 API. With io.open(dfilespath + "/" + name, 'wb') as f: Request = service.files().get_media(fileId=dowid)ĭownloader = MediaIoBaseDownload(fh, request) Listfolders(service, item, des+"/"+item) # LOOP un-till the files are foundĭownloadfiles(service, item, item, des)ĭef downloadfiles(service, dowid, name,dfilespath): PageSize=1000, q="\'" + filid + "\'" + " in parents",įields="nextPageToken, files(id, name, mimeType)").execute() # If modifying these scopes, delete the file token.pickle.
Use Drive credentials.json Downloaded from your Drive API from _future_ import print_functionįrom googleapiclient.discovery import buildįrom google_auth_oauthlib.flow import InstalledAppFlowįrom import Requestįrom apiclient.http import MediaFileUpload, MediaIoBaseDownload