1

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.

2 Answers 2

1

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:

  • if you're using a "Dropbox API" app, your code should look like:
dbx = dropbox.Dropbox(_dropbox_token)

dbx.files_list_folder()
  • if you're using a "Dropbox Business API" app, your code should look like:
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.

6
  • Still, I'm not able to get all team folders where I have admin permissions too, so suggest me to get all files and I'm using my team_member_id only. @Greg
    – ngopal
    Commented Jan 24, 2020 at 6:47
  • 1
    @ngopal I see you also posted this on the Dropbox forum so I'll follow up with you there: dropboxforum.com/t5/Discuss-Developer-API/…
    – Greg
    Commented Jan 24, 2020 at 18:00
  • The DropboxTeam object doesn't have a .files_list_folder() method. Commented Sep 16, 2022 at 21:34
  • @ScottSmith That's correct, files_list_folder is available on Dropbox, e.g., as returned by the DropboxTeam.as_user in the code above.
    – Greg
    Commented Sep 17, 2022 at 2:44
  • Ah you do show that, but not how to get the member_id, and then use it to do what the OP asks. Both of which are present in the other answer. Commented Sep 17, 2022 at 10:03
1

For Dropbox Business API below python code helps downloading files from dropbox.

#function

code

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
1
  • This is the right answer, and the only place I've found on the web to actually show how to get data from a team dropbox. Suggest tidying it up! (Your def is outside the code block.) Commented Sep 17, 2022 at 9:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.