I am trying to list every dropbox team folder and a date against it that specifies the last time a file within was modified.
I have been successful in listing folders with the below script however, the problem is that the folders being listed are only what the "as_admin" account has access to. Is there a way using the admin account to list everything regardless of folder access? I have full control of the api scope so if there is something there, I can easily change it.
def establish_connection():
# Create an instance of the Dropbox API client
try:
dbx_team = dropbox.DropboxTeam(os.environ['ACCESS_TOKEN'])
# get the team member id for common user
members = dbx_team.team_members_list()
dbx_team = dropbox.DropboxTeam(os.environ['ACCESS_TOKEN']).as_admin("")
except AuthError as e:
print(f"Error connecting to Dropbox API: {e}")
exit()
return dbx_team
def list_team_folders():
dbx_team = establish_connection()
folders = []
result = dbx_team.files_list_folder(path='')
while True:
for entry in result.entries:
if isinstance(entry, dropbox.files.FolderMetadata):
folders.append(entry.path_display)
if not result.has_more:
break
result = dbx_team.files_list_folder_continue(result.cursor)
# Iterate over each folder and get the latest modified date of its files
for folder in folders:
latest_modified = datetime(1970, 1, 1) # Set to an arbitrary old date
result = dbx_team.files_list_folder(path=folder)
while True:
for entry in result.entries:
if isinstance(entry, dropbox.files.FileMetadata):
# Check if this file was modified more recently than the current latest modified date
modified = datetime.strptime(str(entry.client_modified), '%Y-%m-%d %H:%M:%S')
if modified > latest_modified:
latest_modified = modified
if not result.has_more:
break
result = dbx_team.files_list_folder_continue(result.cursor)
print(f'{folder}: {latest_modified}')