Discuss Dropbox Developer & API
Hi all,
I have a shared link looking like this: https://www.dropbox.com/sh/o0qb...
In this link I have folders and subfolder and some heavy files in them.
I searched across the web and didn't find anything that could help me.
I basically want to be able to iterate over the folders and the subfolders and download files from specific subfolders.
I am working with Python and the best I could do so far was retrieve the subfolders names and id's (by using this theard )
Do you have any idea how to tackle it?
Thanks!
Here's the HTTP documentation and here's the Python documentation (see the dropbox.dropbox subpage).
For HTTP requests, the /download, /get_shared_link_file, and /list_folders endpoints sound like they would be helpful.
For the Python library, check out the files_download, files_download_to_file, and files_list_folder functions.
The dropbox API is very complex, so you'll need to read through the documentation to see what all is available.
@avieini Yes, as Pikamander2 mentioned, there are some methods that can help with this, like files_list_folder from the thread you linked to, as well as sharing_get_shared_link_file.
Here's a basic example of what using those may look like:
import dropbox ACCESS_TOKEN = "..." url = "https://www.dropbox.com/sh/..." dbx = dropbox.Dropbox(ACCESS_TOKEN) shared_link = dropbox.files.SharedLink(url=url) print(dbx.files_list_folder(path="", shared_link=shared_link)) filename = "..." print(dbx.sharing_get_shared_link_file(url=url, path=filename))
Hi Greg, thanks for your answer
The point that I get confused with is how do I (iteratively) acess the subfolders of the main folder ?
The files_list_folder method only gives me the names and the ids of those subfolders.
If I could "enter" each subfolder I would be able to downlaod it's files.
Hope now it's clearer.
@avieini While the 'files_list_folder' method does not support the native 'recursive' mode when listing from a shared link, you can iteratively list out the contents of the subfolders, by calling again with the relevant 'path' value(s). For example, say if I make the first call:
print(dbx.files_list_folder(path="", shared_link=shared_link))
If that shows me that there is a subfolder with a 'name' of 'another folder', for example, I can then call again to list that one, like:
print(dbx.files_list_folder(path="/another folder", shared_link=shared_link))
That will give the listing for that subfolder, and then likewise I can call 'sharing_get_shared_link_file' to download a file from inside that subfolder, like:
print(dbx.sharing_get_shared_link_file(url=url, path="/another folder/test.txt"))
Hi there!
If you need more help you can view your support options (expected response time for a ticket is 24 hours), or contact us on Twitter or Facebook.
For more info on available support options, see this article.
If you found the answer to your question, please 'like' the post to say thanks to the user!