cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
What’s new: end-to-end encryption, Replay and Dash updates. Find out more about these updates, new features and more here.

Discuss Dropbox Developer & API

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Re: Dropbox for Business with SwiftyDropbox integration

Dropbox for Business with SwiftyDropbox integration

HELPHELPHELP
Explorer | Level 4
Go to solution

Hello,

I am moving my iphone app from a test account with personal dropbox to dropbox for business with team members. This seems to be quite the jump and the documentation is minimal for this particular application. I have already made a new app with team file access. I can log in with the app and it filters registered from unregistered users. That is as far as I can go.

I really need to figure the swift code to allow the users to gain access to their files. list, download, upload, and delete all required. From what I have learned so far I need to get the member ID of the person who just logged in and use it to get the files. So far I do not see any swift way to do this. Does it exist? I'm sure it does. Please, please, please help me find it. If I can get this working we are signing up with close to 100 accounts but I have to get out of beta with the trial. Thanks for everything.

1 Accepted Solution

Accepted Solutions

Greg-DB
Dropbox Staff
Go to solution

If the code doesn't seem to be running or responding, I recommend stepping through with the debugger first to determine where it's breaking down. 

For instance, in the code sample I shared, 'DropboxClientsManager.authorizedTeamClient' needs to be set, in order to make the API calls. That gets set during the authorization process for the Business API app. Is it properly set when you try to make the calls?

Looking at the code you shared for the authorization process, it looks like you are still using the user methods, instead of the team methods. That is, per the docs here, in this case you should use 'setupWithTeamAppKey' instead of 'setupWithAppKey', and 'handleRedirectURLTeam' instead of 'handleRedirectURL'.

View solution in original post

3 Replies 3

Greg-DB
Dropbox Staff
Go to solution

It sounds like you're switching from a "Dropbox API" app registration to a "Dropbox Business API" app registration.

Just for reference, "Dropbox API" apps can be connected to any kind of Dropbox account individually (including Business accounts) in order to access the files in that account. For example, you can list, download, upload, and delete files/folders.

"Dropbox Business API" apps can be connected only to entire Dropbox Business teams, in order to operate on the team and its members. You only need a "Dropbox Business API" app if you want to connect to Business teams only, to access functionality specific to Business teams. For example, you can add and remove members. Additionally, Dropbox Business API apps with the "team member file access" permission in particular can additionally operate on the files in the account of any member of the team.

So, to answer your specific questions, if you have a Dropbox Business API app and want to get the ID of the specific team admin that authorized the access token you're currently using, you can use the tokenGetAuthenticatedAdmin method. You can also use the membersList and membersListContinue methods to get the information, including member IDs, of all of the members of the team.

And since you have a Dropbox Business API app with the "team member file access" permission, you can can get a DropboxClient for any member in particular from DropboxTeamClient, so that you can call file methods, such as listFolder/listFolderContinue, download, upload, and deleteV2 for that account.

Here's a basic example of what it would look like to list the contents of the member folder for the admin who authorized the app to access their team:

DropboxClientsManager.authorizedTeamClient?.team.tokenGetAuthenticatedAdmin().response(completionHandler: { (response, error) in
    if let response = response {
        let currentAdminId = response.adminProfile.teamMemberId
        DropboxClientsManager.authorizedClient = DropboxClientsManager.authorizedTeamClient?.asMember(currentAdminId)
        DropboxClientsManager.authorizedClient!.files.listFolder(path: "").response(completionHandler: { (response, error) in
            if let response = response {
                print(response)
            } else if let error = error {
                print(error)
            }
        })
    } else if let error = error {
        print(error)
    }
})

HELPHELPHELP
Explorer | Level 4
Go to solution

So I tried your code and I get no response. It must be before this that I am causing the issue. It isn't much though.

This is my current method to Authorize. should I be doing this different

 

AppDelegate:

DropboxClientsManager.setupWithAppKey("App_Key")

UIButtonAction:

 


DropboxClientsManager.authorizeFromController(UIApplication.shared, controller: self, openURL: { (url: URL) -> Void in UIApplication.shared.open(url, options: [:], completionHandler: nil) })

Any ideas? Thanks so much.

 

Greg-DB
Dropbox Staff
Go to solution

If the code doesn't seem to be running or responding, I recommend stepping through with the debugger first to determine where it's breaking down. 

For instance, in the code sample I shared, 'DropboxClientsManager.authorizedTeamClient' needs to be set, in order to make the API calls. That gets set during the authorization process for the Business API app. Is it properly set when you try to make the calls?

Looking at the code you shared for the authorization process, it looks like you are still using the user methods, instead of the team methods. That is, per the docs here, in this case you should use 'setupWithTeamAppKey' instead of 'setupWithAppKey', and 'handleRedirectURLTeam' instead of 'handleRedirectURL'.

Need more support?