pythondropboxdropbox-api

Dropbox API (Python) - How to get access to Team and User files


I have a dropox business user which is member of the team. I would like to see the filesystem with the API like when I just login to dropbox.com: Member and team files and folder.

So I'm creating a dropbox authentication code with:

dropbox.DropboxOAuth2FlowNoRedirect(
    settings.DROPBOX_APP_KEY, 
    settings.DROPBOX_APP_SECRET,
    token_access_type="offline",
    scope=[
        "account_info.read",
        "file_requests.read",
        "file_requests.write",
        "files.content.read",
        "files.content.write",
        "files.metadata.read",
        "files.metadata.write",
        "files.team_metadata.read",
        "files.team_metadata.write",
        "sharing.read sharing.write",
        "team_data.content.read",
        "team_data.content.write",
        "team_data.governance.read",
        "team_data.governance.write",
        "team_data.member",
        "team_data.team_space",
    ],        
)

Now i create dbx_client and call function dbx.file_list_folders(). I get error:

This API function operates on a single Dropbox account, but the OAuth 2 access token you provided is for an entire Dropbox Business team.  Since your API app key has team member file access permissions, you can operate on a team member\'s Dropbox by providing the "Dropbox-API-Select-User" HTTP header or "select_user" URL parameter to specify the exact user <https://www.dropbox.com/developers/documentation/http/teams>.')

I can do something like that:

dbx_team = dropbox.DropboxTeam(ACCESS_TOKEN)
dbx = dbx_team.as_user("YOUR_TEAM_MEMBER_ID")

But then I need to know the "YOUR_TEAM_MEMBER_ID" - And it is not possible to get it from API. Or is it?

I just want access to files and folders of me and teams like when I login to dropbox.com in browser. How do manage that with the python dropbox API?


Solution

  • Answer from dropbox forum:

    When utilizing team scopes, it's necessary to have a specific team admin account to authorize the app. However, this authorization applies to the entire team, not merely the authorizing account. To determine the account that authorized a team-linked access token, you can use the /2/team/token/get_authenticated_admin (team_token_get_authenticated_admin) endpoint. If your intention is solely to link to one account, it's advisable to exclude team scopes from your configuration. This way, the connection will be established directly with the specific account, eliminating the need to employ as_user in the process.