We are aware of the issue with the badge emails resending to everyone, we apologise for the inconvenience - learn more here.
Forum Discussion
JuliaNowicka
3 years agoExplorer | Level 4
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...
- 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')
Greg-DB
3 years agoDropbox Staff
[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')
- JuliaNowicka3 years agoExplorer | Level 4
Thank you so much Greg! Exactly what I was looking for! Can I do something similar to check team folders?
- Greg-DB3 years agoDropbox Staff
Yes, team folders are considered a type of shared folder, so just building on the previous sample, you can do something like this:
team_folder_count = len([shared_folder for shared_folder in shared_folders if shared_folder.is_team_folder]) if team_folder_count == 0: print('User has no team folders') else: print('User has at least one team folder') print('User has %s team folder(s)' % team_folder_count)
Note though that this will only catch "team folders", not "team spaces". Any Dropbox Business team may be using one of those two different configurations. Check out the Team Files Guide for information on that.
- JuliaNowicka3 years agoExplorer | Level 4
Thank you Greg, I will try that.
About Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.
5,877 PostsLatest Activity: 12 months agoIf 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!