dropbox / dropbox-sdk-python

The Official Dropbox API V2 SDK for Python
https://www.dropbox.com/developers
MIT License
932 stars 317 forks source link

sample code for team #405

Closed alicera closed 2 years ago

alicera commented 2 years ago

Do you have the sample code for team?

greg-db commented 2 years ago

You can find all of the example code for the Python SDK here: https://github.com/dropbox/dropbox-sdk-python/tree/main/example That doesn't include anything written specifically for Business teams though.

Is there some functionality in particular that you're having trouble with? If so, please share the details so we can take a look.

alicera commented 2 years ago

https://qiita.com/tksnino/items/ee624221d3da00c89005 This code work for me. But change the member to team, it doesnt work. Could you fix the code for team? I appreciate your help very much

greg-db commented 2 years ago

Can you clarify what you mean when you say you "change the member to team, it doesnt work"? Please show the specific code you're running and whatever unexpected error or output you're getting.

alicera commented 2 years ago

If I create a folder, dropbox will show only you or specific user.

Assume the work team name work_team. If I crate a folder, dropbox will show the work_team or specific user

like this image

Now I put the data into the public folder and run the project(# https://qiita.com/tksnino/items/ee624221d3da00c89005). I can't search the folder "public". But I can search the folder "private".

res = self .dbx.files_list_folder( self .DB_ROOT_DIR, recursive = True )
.local/lib/python3.8/site-packages/dropbox/base.py", line 1952, in files_list_folder
r = self.request(
File "/home/test/.local/lib/python3.8/site-packages /dropbox/dropbox_client.py", line 348, in request
raise ApiError(res.request_id,

dropbox.exceptions.ApiError: ApiError('74923a3b6e1', ListFolderError('path', LookupError('not_found', None)))
greg-db commented 2 years ago

It looks like you're referring to accessing the contents of the "team space", instead of just the "member folder". By default, Dropbox API calls operate in the "member folder", not the "team space", but you can configure them to operate in the team space when desired, by setting the "Dropbox-API-Path-Root" header. For information on how to do so, please refer to the Team Files Guide:

https://developers.dropbox.com/dbx-team-files-guide

With the Python SDK in particular, you can set that header by using the with_path_root method:

https://dropbox-sdk-python.readthedocs.io/en/latest/api/dropbox.html#dropbox.dropbox_client.Dropbox.with_path_root

That would look like this (with root_namespace_id and path being your relevant values): dbx.with_path_root(dropbox.common.PathRoot.root(root_namespace_id)).files_list_folder(path)

antortjim commented 2 years ago

I got it to work with a Dropbox Business account thanks to this trick. The issue I was facing is that indeed, the default root dir is the user's home folder, so all Team Shared folders standing side by side with the user home folder became invisible. This was to me unintuitive, since they are perfectly visible in the dropbox web GUI https://www.dropbox.com/work I found the root_namespace_id by running the API function users_get_current_account() and fetching the root_info.root_namespace_id attribute of the result of the call. This call works as long as the team_data.member permission is not granted in the Team Scopes section of the Permission tab in the application dashboard (available at https://www.dropbox.com/developers/apps/info/<APP_KEY>#permissions )