Hi Dropbox Forum,
I want to get team root folder by SwiftyDropbox. but fail.
this is what I do
1.Set .plist file
2.Set AppKey in AppDelegate
DropboxClientsManager.setupWithAppKey("xxxxxxx")
3.authorization(use team account login)
if let _ = DropboxClientsManager.authorizedTeamClient {
DropboxClientsManager.unlinkClients()
}
if let _ = DropboxClientsManager.authorizedClient {
DropboxClientsManager.unlinkClients()
}
DropboxClientsManager.authorizeFromController(UIApplication.shared,
controller: self,
openURL: { (url: URL) -> Void in
UIApplication.shared.open(url, options: [:], completionHandler: {success in
if success{
print("Open URL success")
}else{
print("Open URL fail")
}
})
})
4. then in AppDelegate
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any]) -> Bool
let oauthCompletion: DropboxOAuthCompletion = {
if let authResult = $0 {
switch authResult {
case .success:
print("Success! User is logged into DropboxClientsManager.")
let a = client?.users.getCurrentAccount()
a?.response(completionHandler: { user, error in
print("user:\(user), error: \(error)")
print("accountType:\(user?.accountType)")
print("rootNamespaceId:\(user?.rootInfo.rootNamespaceId)")
})
case .cancel:
print("Authorization flow was manually canceled by user!")
case .error(_, let description):
print("Error: \(String(describing: description))")
let hud = MBProgressHUD.showAdded(to: UIApplication.shared.keyWindow!, animated: true)
hud.label.text = "Login failed"
hud.hide(animated: true, afterDelay: 1)
}
}
}
DropboxClientsManager.handleRedirectURL(url, completion: oauthCompletion)
5. Set a button to listFolder
I see this post "Using the Dropbox-API-Path-Root Header", but don't know how to set it in SwiftyDropbox.
https://www.dropbox.com/lp/developers/reference/dbx-team-files-guide#namespaces
func getList(){
let client = DropboxClientsManager.authorizedClient?.withPathRoot(.namespaceId("xxxxxx"))//root_namespace_id get from oauthCompletion
client?.users.getCurrentAccount().response(completionHandler: {user, error in print("user:\(user) error:\(error)")})
client?.files.listFolder(path: filePath ,includeMountedFolders: true).response(completionHandler: {response, error in
if response?.entries != nil{
self.parseDropboxEntries(entries: response!.entries)
}
})
}
it show error and can't list folder:
Spoiler
Can anyone help me ? thank you