Reputation: 14317
I am using Python SDK and would like to retrieve all of my dropbox files and folders.
I am using v2 of Python SDK of Dropbox.
dbx = Dropbox("DROBOX_ACCESS_TOKEN")
response = dbx.files_list_folder("/Apps/Marketing")
for file in response.entries:
print file.name
However, I get an error:
dropbox.exceptions.ApiError: ApiError('b0479a07aaa5a9b405862ae75cbf135d', ListFolderError(u'path', LookupError(u'not_found', None)))
While Apps folder exists in Dropbox when I login (prob in root folder)
When I try to list with empty path in order to get root folder folders:
response = dbx.files_list_folder("")
the response entries are empty.
How can I retrieve the list of all files and folders in dropbox v2 api?
The token is the one I generated in OAuth 2 settings in dropbox.
and I gave the token App folder access to a folder under Apps called Marketing.
Upvotes: 9
Views: 18881
Reputation: 923
If you have a large number of files, a simple call to dbx.files_list_folder()
will only return a portion of your files -- it returns only 500 files for me. In order to get all the remaining files, you can make use of a cursor
along with the dbx.files_list_folder_continue()
as follows:
dbx = get_dropbox_client()
folder_path = '' # root folder
all_files = [] # collects all files here
has_more_files = True # because we haven't queried yet
cursor = None # because we haven't queried yet
while has_more_files:
if cursor is None: # if it is our first time querying
result = dbx.files_list_folder(folder_path)
else:
result = dbx.files_list_folder_continue(cursor)
all_files.extend(result.entries)
cursor = result.cursor
has_more_files = result.has_more
print("Number of total files listed: ", len(all_files))
print("All filenames: ", [entry.name for entry in all_files])
Upvotes: 0
Reputation: 742
dbx = Dropbox("DROBOX_ACCESS_TOKEN")
response = dbx.files_list_folder(path=DROPBOX_INPUT_PATH)
print(response)
Upvotes: 1
Reputation: 32484
I am using Python SDK and would like to retrieve all of my dropbox files and folders.
...
and I gave the token App folder access to a folder under Apps called Marketing.
You should have given your app Full Dropbox access type. With App Folder access type, your app is automatically restricted to the corresponding folder under Apps
, and hence all paths passed to files_list_folder()
running under that app are interpreted relative to your app's dedicated folder.
Upvotes: 11