简体   繁体   English

使用 Python SDK 从 Dropbox Team 文件夹下载文件

[英]Download files from Dropbox Team folder using Python SDK

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.我正在尝试从 Dropbox Team 文件夹下载文件,按照 StackOverflow 不同帖子的建议,我尝试使用 files_list_folder() 创建访问密钥,但是,dropboxTeam 类无法访问此方法。

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.整个想法是从文件夹的文件夹中获取文件列表,循环遍历它们并下载。

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 . files_list_folder方法在特定 Dropbox 用户的帐户上运行,而不是在整个 Dropbox 团队上运行,因此它只存在于dropbox.Dropbox ,而不存在于dropbox.DropboxTeam The same applies to files_list_folder_continue , files_download , etc.这同样适用于files_list_folder_continuefiles_download等。

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.如果您只需要连接到个人 Dropbox 帐户以访问该帐户中的文件(无论该帐户是否属于 Dropbox Business 团队),您可以注册一个“ Dropbox API ”应用程序并使用以下命令直接创建一个dropbox.Dropbox对象连接到您的应用程序的任何用户的访问令牌。

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.如果您确实需要能够连接到整个 Dropbox Business 团队的任何成员,您应该注册一个“ Dropbox Business API ”应用并使用生成的访问令牌创建一个dropbox.DropboxTeam对象。 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.该对象适用于整个团队,但您可以使用“团队成员文件访问”功能通过DropboxTeam.as_userDropboxTeam.as_admin方法访问特定成员的帐户。

So in summary:所以总结一下:

  • if you're using a "Dropbox API" app, your code should look like:如果您使用的是“Dropbox API”应用,您的代码应如下所示:
dbx = dropbox.Dropbox(_dropbox_token)

dbx.files_list_folder()
  • if you're using a "Dropbox Business API" app, your code should look like:如果您使用的是“Dropbox Business API”应用,您的代码应如下所示:
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 .此外,有关如何访问 Dropbox 帐户的不同部分(例如团队文件夹)的信息,请查看命名空间指南内容访问指南 To set the Dropbox-API-Path-Root Header mentioned in the Namespace Guide , use the Dropbox.with_path_root method.要设置命名空间指南中提到的Dropbox-API-Path-Root标头,请使用Dropbox.with_path_root方法。

For Dropbox Business API below python code helps downloading files from dropbox.对于下面的 Dropbox Business API,python 代码有助于从 Dropbox 下载文件。

#function #功能

code代码

def dropbox_file_download(access_token,dropbox_file_path,local_folder_name): 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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM