Reputation: 219
I'm trying to download files from the Dropbox Team folders, Created Access Key I tried with files_list_folder() as suggested from different posts from StackOverflow, But, This method is not accessible with dropboxTeam class.
dbx = dropbox.DropboxTeam(_dropbox_token)
dbx.files_list_folder() # here this method not showing
So, Help me to do it. The whole idea is to get the list of files from folder of folders loop through them and download.
Upvotes: 1
Views: 2551
Reputation: 39
For Dropbox Business API below python code helps downloading files from dropbox.
#function
def dropbox_file_download(access_token,dropbox_file_path,local_folder_name):
try:
dropbox_file_name = dropbox_file_path.split('/')[-1]
dropbox_file_path = '/'.join(dropbox_file_path.split('/')[:-1])
dbx = dropbox.DropboxTeam(access_token)
# get the team member id for common user
members = dbx.team_members_list()
for i in range(0,len(members.members)):
if members.members[i].profile.name.display_name == logged_user_name:
member_id = members.members[i].profile.team_member_id
break
# connect to dropbox with member id
dbx = dropbox.DropboxTeam(access_token).as_user(member_id)
# list all the files from the folder
result = dbx.files_list_folder(dropbox_file_path, recursive=False)
# download given file from dropbox
for entry in result.entries:
if isinstance(entry, dropbox.files.FileMetadata):
if entry.name == dropbox_file_name:
dbx.files_download_to_file(local_folder_name+entry.name, entry.path_lower)
return True
return False
except Exception as e:
print(e)
return False
Upvotes: 1
Reputation: 16930
The files_list_folder
method operates on a specific Dropbox user's account, not on an entire Dropbox team, so it only exists on dropbox.Dropbox
, not dropbox.DropboxTeam
. The same applies to files_list_folder_continue
, files_download
, etc.
If you just need to connect to individual Dropbox accounts to access the files in that account (whether or not the account is part of a Dropbox Business team), you can register a "Dropbox API" app and directly create a dropbox.Dropbox
object using the access token for any user that connects to your app.
If you do need to be able to connect to any member of an entire Dropbox Business team, you should instead register a "Dropbox Business API" app and use the resulting access token to create a dropbox.DropboxTeam
object. That object applies to the whole team, but you can then use the "team member file access" feature to access a specific member's account, via the DropboxTeam.as_user
or DropboxTeam.as_admin
method.
So in summary:
dbx = dropbox.Dropbox(_dropbox_token)
dbx.files_list_folder()
dbx = dropbox.DropboxTeam(_dropbox_token).as_user(member_id)
dbx.files_list_folder()
Also, for information on how to access different parts of a Dropbox account, such as a team folder, check out the Namespace Guide and Content Access Guide. To set the Dropbox-API-Path-Root
Header mentioned in the Namespace Guide, use the Dropbox.with_path_root
method.
Upvotes: 1