We Want to Hear From You! What Do You Want to See on the Community? Tell us here!
Forum Discussion
Tobiwan
3 years agoNew member | Level 2
Problem with listing team folder with python SDK: Error in call to API function "files/list_folder
Hi Everyone!
First of all im new to this so please dont take me to harsh if im using wrong vocabulary or im saying dumb stuff haha 😄
So i have a big folder which contains 10.000 folders each containing again around 5 image files in my Team Directory. I want to create a download link for every file using the python sdk. I created an app and got my token. Then I got my, team_space_namespace_id (list_folders), ng_member_id (get_current_account) with the green functions(?) in postman. Then i pasted them into this python script:
import dropbox as dbx
dropbox_token = <access token>
team_space_namespace_id = <team_space_namespace_id>
ng_member_id = <ng_member_id >
output = dbx.DropboxTeam(dropbox_token).with_path_root(dbx.common.PathRoot.root(team_space_namespace_id)).as_admin(ng_member_id).files_list_folder("").entries
print(output)
I got the "DropboxTeam" Line because when i list the noremal directory only my personal directory is shown but i wanted the Team Folder. When I Executed it i got the following error:
dropbox.exceptions.BadInputError: BadInputError('540abf5f823f4f699855a087034d2339', 'Error in call to API function "files/list_folder": Unexpected select user header. Your app does not have permission to use this feature')
I couldnt find the files/list_folder permission in the app settings and there are all und "Files and Folders" and "Account Info" activated. So whats the problem here? Thank you for any help!
Kind regards,
Tobi
4 Replies
- Greg-DB3 years ago
Dropbox Community Moderator
I see you're getting the error: "Unexpected select user header. Your app does not have permission to use this feature". This error indicates that you're supplying the "Dropbox-API-Select-User" or "Dropbox-API-Select-Admin" request header (via the 'as_user' or 'as_admin' method, respectively), but are using an access token for an app that does not have access to this feature. This is the "member file access" feature, meant for use by Dropbox Business API apps with the "team member file access" permission or scoped apps with the 'team_data.member' scope, to enable an app to be connected to an entire team and operate on behalf of any team member.
Since you are just trying to interact with files/folders in your account though (even if they happen to be in a team folder), you don't need that functionality, so you can omit the '.as_admin(ng_member_id)' from your code and instead just do something like this:
output = dbx.Dropbox(dropbox_token).with_path_root(dbx.common.PathRoot.root(team_space_namespace_id)).files_list_folder("").entries print(output)
- Tobiwan3 years agoNew member | Level 2
Ok really nice thank you! I had to change the team ID but then i could get the metadata from The Team folder! But How do i use the
"sharing_create_shared_link_with_settings" method in that context?
Also when i use this code to display all directories in "baked textures) (the 10k folder folder :D):
for entry in dbx.Dropbox(dropbox_token).with_path_root(dbx.common.PathRoot.root(team_space_namespace_id)).files_list_folder("/Baked Textures").entries:print(entry.name)The subfolders get printed only to around 1500 and in a weird order. For the 1500 i probably have to use recusion again right but how do i activate it in that context? The order is for example:
1038
1039
1040
1042
1043
1044
1045
1047
1
10000
1048
1049Thank you for yoour help already!Tobi - Здравко3 years agoLegendary | Level 20
Tobiwan wrote:...
The subfolders get printed only to around 1500 and in a weird order. For the 1500 i probably have to use recusion again right but how do i activate it in that context? ...
Hi Tobiwan,
Currently, in your code, you are using only files_list_folder method. This method starts content listing process and can fetch the list entirely if it's small enough, but you don't have to rely on! Within the retrieved result is a field 'has_more' (i.e. are some entries lefts to be fetched). If there are, you have to continue listing using files_list_folder_continue method until there are no more entries left. On every pagination step, cursor take place within result; a cursor which you have to use as argument on following call. In such a way you will no more be limited to entries number able to be got out from single call.
Recursion can be activated using the corresponding argument (the same named) in the initial listing step. 😉 There are other parameters too that control the listing process; take a look there. Listing order can't get controlled; it's something internal, you shouldn't rely on.
Hope this helps.
- Greg-DB3 years ago
Dropbox Community Moderator
Tobiwan As Здравко instructed, make sure you implement support for the pagination in order to be able to retrieve all entries. Refer to the documentation they linked to for more information.
As for sharing_create_shared_link_with_settings, you can call it the same way, like this:
output = dbx.Dropbox(dropbox_token).with_path_root(dbx.common.PathRoot.root(team_space_namespace_id)).sharing_create_shared_link_with_settings("/test.txt") print(output)
Be sure to plug in your actual path, in place of my example "/test.txt". You can programmatically get the path for an entry from Metadata.path_lower, for instance.
About Discuss Dropbox Developer & API
Make connections with other developers815 PostsLatest Activity: 2 hours ago
The Dropbox Community team is active from Monday to Friday. We try to respond to you as soon as we can, usually within 2 hours.
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!