cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Want to learn some quick and useful tips to make your day easier? Check out how Calvin uses Replay to get feedback from other teams at Dropbox here.

Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

list_folder/continue returning same ID for multiple files in folder

list_folder/continue returning same ID for multiple files in folder

time4116
Explorer | Level 4

I'm having an issue downloading content from a team admins account (I'm using a dropbox buisness API with team member file access). There are several shared folders that this team admin is an owner of. However, when I run the below code I see an entry for each target item in the folder but they all have the same ID. I've only provided the code for list_folder and list_folder/continue because I'm not seeing the files to download from those functions. Some of the target folders are shared with members outside of the team but this doesn't seem to matter for some of the folders in the account because I can download those. Any help would be greatly appreciated.

 

Edit*: I believe that this has something to do with my listUserFolderContinue() function as if I specify the folder explicitly I am able to download the folder. I don't think I'm returning all of the results, can anyone help out on where I went wrong?

 

import requests

# Dropbox Business API with Team member file access)
token = 'My Key'

def listUserFolder(dbmid):
    global allFiles

    headers = {
        'Authorization': 'Bearer {}'.format(token),
        'Content-Type': 'application/json',
        'Dropbox-API-Select-User': dbmid
    }

    data = '{"path": "","recursive": true,"include_media_info": false,"include_deleted": false,"include_has_explicit_shared_members": false,"include_mounted_folders": true}'

    response = requests.post('https://api.dropboxapi.com/2/files/list_folder', headers=headers, data=data)
    json = response.json()
    allFiles += json['entries']
    return json

def listUserFolderContinue(dbmid):
    global allFiles

    json = listUserFolder(dbmid)

    while json['has_more']:

        cursorline = json['cursor']
        cursor = '{"cursor": "' + cursorline + '"}'
        data = '{}'.format(cursor)

        headers = {
            'Authorization': 'Bearer {}'.format(token),
            'Content-Type': 'application/json',
            'Dropbox-API-Select-User': dbmid
        }

        response = requests.post('https://api.dropboxapi.com/2/files/list_folder/continue', headers=headers, data=data)
        json = response.json()
        allFiles += json['entries']
        return allFiles

 

3 Replies 3

chirstius
Dropbox Staff

Hello @time4116,

 

Can you clarify what you mean by 'all have the same ID'? Every entry you get back has the same file/folder ID?

 

Aside from that, when calling /list_folder and /list_folder_continue you should be sure to follow the processing guidelines given in the documentation around how to process each entry (in the description):
https://www.dropbox.com/developers/documentation/http/documentation#files-list_folder

 

Also, currently there may be some issues with your flow control logic. If you are calling your listUserFolder() method first, and then calling listUserFolderContinue() afterwards - you'll end up calling listUserFolder() again since it's called within listUserFolderContinue() which will reset your cursor. Also, you have your return in listUserFolderContinue() within your while loop indentation/scope which means you'll never loop more than once before returning from the method.

 

You only need to call the /list_folder endpoint once, then you can call the /list_folder_continue endpoint many times, as long as has_more is true. You'll always get a cursor back, and you can even persist that cursor for long periods between subsequent script runs and just keep calling list_folder_continue to get an update on the current state of the user's content (again you MUST follow the guidelines for processing in the documentation for this to work properly).

 

Hope this gets you pointed in the right direction,

 

-Chuck

time4116
Explorer | Level 4

Thanks @chirstius. Please disregard the same ID bit. I was only calling the listUserFolderContinue() function, I think I may have made a mistake on the formating in my intial code post as the return statement should be outside of the while loop. Turns out that I was not able to return the list because I did not account for receiving a 500 error of which would not contain any json['entries'] and therefore brick the script when trying to add to the array. Will I need to implement retry logic or will the preceding cursors display any missed metadata?

chirstius
Dropbox Staff

@time4116 you should be good using the previous cursor as long as you follow the processing guidance from the list_folder documentation.

Need more support?
Who's talking

Top contributors to this post

  • User avatar
    chirstius Dropbox Staff
  • User avatar
    time4116 Explorer | Level 4
What do Dropbox user levels mean?