正在列出使用Dropbox API的文件



我正在尝试使用官方的Dropbox SDK for Python访问存储在Dropbox上的文件。。我尝试了几种方法来输入目录名,我想根据从这个链接中获取的脚本列出目录名的内容https://practicaldatascience.co.uk/data-science/how-to-use-the-dropbox-api-with-python.按照本网站中的说明,我创建了一个应用程序,生成了一个dropbox访问令牌(生成了'long-gibberish'(,并授予自己Files and Folders的读取权限。

当我通过网站登录Dropbox时,我想访问的文件夹的文件夹结构如下:folder/SubFolder/SubSubFolder。

DROPBOX_ACCESS_TOKEN = 'long-gibberish' 
def dropbox_connect():
"""Create a connection to Dropbox."""
try:
dbx = dropbox.Dropbox(DROPBOX_ACCESS_TOKEN)
except AuthError as e:
print('Error connecting to Dropbox with access token: ' + str(e))
return dbx
def dropbox_list_files(path):
"""Return a Pandas dataframe of files in a given Dropbox folder path in the Apps directory.
"""
dbx = dropbox_connect()
try:
files = dbx.files_list_folder(path).entries
files_list = []
for file in files:
if isinstance(file, dropbox.files.FileMetadata):
metadata = {
'name': file.name,
'path_display': file.path_display,
'client_modified': file.client_modified,
'server_modified': file.server_modified
}
files_list.append(metadata)
df = pd.DataFrame.from_records(files_list)
return df.sort_values(by='server_modified', ascending=False)
except Exception as e:
print('Error getting list of files from Dropbox: ' + str(e))

我在调用函数时得到以下错误:

dropbox_list_files('Folder/SubFolder/SubSubFolder')

Error getting list of files from Dropbox: ApiError('short-gibberish', ListFolderError('path', LookupError('not_found', None)))

我想得到一些关于如何设置正确的path的帮助。

在找到Python教程的Dropbox后,发现可以通过以下方式检索目录结构

for entry in dbx.files_list_folder('').entries:
print(entry.name)

但是,在此之前,必须创建Dropbox对象的实例:

dbx = dropbox.Dropbox('YOUR_ACCESS_TOKEN')

这是通过调用和分配dbx:来实现的

dbx = dropbox_connect()

最新更新