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

Forum Discussion

jraymonds's avatar
jraymonds
Explorer | Level 4
2 years ago

Trouble enumerating directories in a team space with SwiftyDropbox on macOS

I know this is a newbie issue but I cannot seem to find the right track to get over this learning curve...   I can successfully authenticate on macOS to this point:   let client = DropboxClients...
  • Greg-DB's avatar
    2 years ago

    jraymonds First, you should decide if you need your app to be linked to the team or linked to the user. When you use any "team scopes", the app would be linked to the entire team itself. If you don't use any team scopes, the app would be linked to the user account only.

     

    If you only need access to user functionality, such as things under FilesRoutes like listFolder/listFolderContinue, it would be best to not enable any team scopes and only use user scopes. That way, the app gets linked to the account and doesn't have unnecessary access to team operations. It would also mean that you don't need to specify the member ID, as its only connected to one account anyway.

     

    Also, whether the app is team-linked to user-linked, you would use DropboxClient.withPathRoot to set the Dropbox-API-Path-Root header if you need to access the team space. Accessing the team space that an connected account has access to doesn't require team scopes. Check out the Team Files Guide for more context on accessing the team space.

     

    You can call getCurrentAccount on UsersRoutes using a DropboxClient.

     

    So, for a user-linked app, you could do something like this:

     

    // DropboxClientsManager.authorizedClient is a DropboxClient
    DropboxClientsManager.authorizedClient!.users.getCurrentAccount().response { response, error in
        if let account = response {
            let rootNamespaceId = account.rootInfo.rootNamespaceId  // this gets the root namespace ID for the account, which is the team space if the account has a team space
            DropboxClientsManager.authorizedClient = DropboxClientsManager.authorizedClient!.withPathRoot(Common.PathRoot.root(rootNamespaceId))  // this sets the root for the client to the root found above, e.g., the team space
            DropboxClientsManager.authorizedClient!.files.listFolder(path: "").response { response, error in
                if let listing = response {
                    print(listing)
                } else {
                    print(error!)
                }
            } // and so on, handling the result and calling listFolderContinue as needed
        } else {
            print(error!)
        }
    }

     

     

    Alternatively, if you do need the app to be team-linked for whatever reason, you would get a DropboxClient from asMember on DropboxTeamClient. You can get a member ID from other methods like tokenGetAuthenticatedAdmin, membersGetInfoV2, membersListV2/membersListContinueV2, etc. on TeamRoutes.

     

About Dropbox API Support & Feedback

Node avatar for Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

5,878 PostsLatest Activity: 2 hours 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!