We are aware of the issue with the badge emails resending to everyone, we apologise for the inconvenience - learn more here.

Forum Discussion

JuliaNowicka's avatar
JuliaNowicka
Explorer | Level 4
3 years ago

Check if user has access to any shared folders

Hi, I'm trying to check if a user has access to any folders. My code at the moment is printing 'User has at least one shared folder' for everyone, but I'm not sure if that's correct. Could someone po...
  • Greg-DB's avatar
    3 years ago

    [Cross-linking for reference: https://stackoverflow.com/questions/73558139/check-if-a-user-has-access-to-any-shared-folders-in-dropbox ]

     

    Yes, for the Python SDK, using the sharing_list_folders/sharing_list_folders_continue methods is the right way to list the shared folders that a user account has access to. The Dropbox API doesn't offer a call just for returning a boolean indicating whether or not an account has any shared folders, so listing and counting them would be the right solution.

     

    Note however that the sharing_list_folders method returns a ListFoldersResult, which is not itself the list of shared folders for that result page. That would be in ListFoldersResult.entries. So, you would instead need to do something like `if len(shared_folders.entries) == 0:` instead.

     

    Also while the `limit` parameter sets a maximum page size, it doesn't technically guarantee a minimum page size, so to be safe it would be best to implement the pagination as documented and check the whole list, like this:

     

    shared_folders = []
    shared_folders_res = dbx.sharing_list_folders()
    shared_folders += shared_folders_res.entries
    while shared_folders_res.cursor:
        shared_folders_res = dbx.sharing_list_folders_continue(cursor=shared_folders_res.cursor)
        shared_folders += shared_folders_res.entries
    
    if len(shared_folders) == 0:
        print('User has no shared folders')
    else: 
        print('User has at least one shared folder')

     

About Dropbox API Support & Feedback

Node avatar for Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

5,877 PostsLatest Activity: 12 months ago
326 Following

If you need more help you can view your support options (expected response time for an email or ticket is 24 hours), or contact us on X or Facebook.

For more info on available support options for your Dropbox plan, see this article.

If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!