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.

ngopal
  • 219
  • 1
  • 2
  • 11

2 Answers2

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.

Greg
  • 16,359
  • 2
  • 34
  • 44
  • 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 Jan 24 '20 at 06:47
  • 1
    @ngopal I see you also posted this on the Dropbox forum so I'll follow up with you there: https://www.dropboxforum.com/t5/Discuss-Developer-API/Not-able-to-get-team-folders-or-files-using-python-sdk/m-p/391999#M958 – Greg Jan 24 '20 at 18:00
  • The DropboxTeam object doesn't have a `.files_list_folder()` method. – Scott Smith Sep 16 '22 at 21:34
  • @ScottSmith That's correct, [`files_list_folder`](https://dropbox-sdk-python.readthedocs.io/en/latest/api/dropbox.html#dropbox.dropbox_client.Dropbox.files_list_folder) is available on [`Dropbox`](https://dropbox-sdk-python.readthedocs.io/en/latest/api/dropbox.html#dropbox.dropbox_client.Dropbox), e.g., as returned by the [`DropboxTeam.as_user`](https://dropbox-sdk-python.readthedocs.io/en/latest/api/dropbox.html#dropbox.dropbox_client.DropboxTeam.as_user) in the code above. – Greg Sep 17 '22 at 02: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. – Scott Smith Sep 17 '22 at 10:03
  • @Greg I'll remove my downvote, but it won't let me unless there is an edit. :( When I saw this wasn't enough to fully solve the problem w/o reading a bunch of referenced docs, I didn't realize what a mess this was. And wouldn't have gotten it figured out w/o your answer and the other one put together. If you make an arbitrary edit I'll remove the downvote! – Scott Smith Sep 19 '22 at 15:21
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
  • 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.) – Scott Smith Sep 17 '22 at 09:59