在Python中获取文件夹中的文件URL

发布于 2025-02-10 19:35:37 字数 485 浏览 1 评论 0 原文

我的Dropbox中有很多文件夹,其中包含图片,我正在尝试在特定文件夹中获取所有图片的列表。

import requests
import json
import dropbox


TOKEN = 'my_access_token'


dbx = dropbox.Dropbox(TOKEN)

for entry in dbx.files_list_folder('/Main/Test').entries:
    # print(entry.name)
    print(entry.file_requests.FileRequest.url)
    # print(entry.files.Metadata.path_lower)
    # print(entry.file_properties.PropertyField)

正确打印条目名称在文件夹中列出了所有文件名,但是其他所有内容'filemetadata'对象没有属性'get_url'

I have a bunch of folders in Dropbox with pictures in them, and I'm trying to get a list of URLs for all of the pictures in a specific folder.

import requests
import json
import dropbox


TOKEN = 'my_access_token'


dbx = dropbox.Dropbox(TOKEN)

for entry in dbx.files_list_folder('/Main/Test').entries:
    # print(entry.name)
    print(entry.file_requests.FileRequest.url)
    # print(entry.files.Metadata.path_lower)
    # print(entry.file_properties.PropertyField)

printing the entry name correctly lists all of the file names in the folder, but everything else says 'FileMetadata' object has no attribute 'get_url'.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

木森分化 2025-02-17 19:35:37

方法返回 listFolderResult ,其中 listfolderresult.entries

另外,请注意,您不能保证您可以从 files_list_folder 方法,因此请确保实现 files_list_folder_continue 。请参阅有关更多信息。

您提到的链接是共享链接自己不包含这样的链接。您可以从 path_lower 。例如,在代码中的循环的中,看起来像 print(entry.path_lower)

您应该使用 列出现有链接和/或 sharing_create_create_shared_shared_link_with_with_settings 根据需要创建任何特定文件的共享链接。

The files_list_folder method returns a ListFolderResult, where ListFolderResult.entries is a list of Metadata. Files in particular are FileMetadata.

Also, note that you aren't guaranteed to get everything back from files_list_folder method, so make sure you implement files_list_folder_continue as well. Refer to the documentation for more information.

The kind of link you mentioned is a shared link. FileMetadata don't themselves contain a link like that. You can get the path from path_lower though. For example, in the for loop in your code, that would look like print(entry.path_lower).

You should use sharing_list_shared_links to list existing links, and/or sharing_create_shared_link_with_settings to create shared links for any particular file as needed.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文