You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
client = gdrive_interact.authenticate_client("creds.txt") # Saves access token credentials. If file does not exist, one-time manual sign-in is done via browser and the file is auto-generated.
gdrive_interact.download_folder(client, "<drive_folder_name>/<drive_folder_name>/.../<drive_folder_name>", "C:/.../<system_directory_name>", files_only=False) # Set files_only = True if you only want the files within, and not the folder itself
37
+
```
38
+
39
+
## How to create a credentials file
40
+
In order to contact and successfully authenticate with your Drive account, you must have a credentials file. In the above example, it is `client_secrets.json`. To create one, see [Google's API Console](console.developers.google.com). Create a project and enable Google Drive API. Download the credentials file.
gauth.SaveCredentialsFile(creds_path) #Note that credentials will expire after some time and may not refresh. When this happens, delete the mycreds.txt file and run the program again. A new and valid mycreds.txt will automatically be created.
38
+
client.drive=GoogleDrive(client.gauth)
39
+
40
+
returnclient
41
+
42
+
43
+
44
+
deflist_files(client, folder_id):
45
+
46
+
# authenticate_client()
47
+
48
+
returnclient.drive.ListFile({'q': f"'{folder_id}' in parents and trashed=false"}).GetList()
49
+
50
+
51
+
defget_id(client, folder_path):
52
+
53
+
fileID=None
54
+
55
+
try:
56
+
57
+
folder_path=folder_path.split('/')
58
+
59
+
fileList=client.drive.ListFile({'q': "'root' in parents and trashed=false"}).GetList()
60
+
61
+
forfileinfileList:
62
+
iffile['title']==folder_path[0]:
63
+
fileID=file['id']
64
+
break
65
+
folder_path.pop(0)
66
+
67
+
forfolder_nameinfolder_path:
68
+
fileList=client.drive.ListFile({'q': f"'{fileID}' in parents and trashed=false"}).GetList()
#If files_only = True, only files will be downloaded. If files_only = False, parent folder containing the files will be downloaded along with its contents.
126
+
# authenticate_client()
127
+
128
+
working_path=os.getcwd()
129
+
130
+
target_id=get_id(client, target_folder_path)
131
+
132
+
iftarget_id==False:
133
+
print(f"[ ERROR in gprocesses.py ] : {target_folder_path} not found.")
0 commit comments