iosswiftdropbox

Dropbox usersGetCurrentAccount no member compiler error


Using IOS 9.1, running on Xcode 7.1.1. under El Capitan. I am trying out the tutorial on accessing dropbox thru their (new maybe) SwiftDropbox library by following this page.

https://blogs.dropbox.com/developers/2015/05/try-out-swiftydropbox-the-new-swift-sdk-for-dropbox-api-v2/

Started well, managed to connect and get authorised, but unable to do much more cause the code posted to their tutorial doesn't compile.

if let client = Dropbox.authorizedClient {
 
    // Get the current user's account info
    client.usersGetCurrentAccount().response { response, error in
        if let account = response {
            println("Hello \(account.name.givenName)")
        } else {
            println(error!)
        }
    }
     
    // List folder
    client.filesListFolder(path: "").response { response, error in
        if let result = response {
            println("Folder contents:")
            for entry in result.entries {
                println(entry.name)
            }
        } else {
            println(error!)
        }
    }

Complaining that DropboxClient has no member "usersGetCurrentAccount" or "filesListFolder" which I assume are some sort method calls {pretty new to swift too}. Cannot seem to Google any useful leads on this? What should this code read/say?


Solution

  • Bon,

    THANKYOU smarx; you put me on the right path. Here is the final code; with two minor fixes to the tutorial he mentioned here.

    //  ViewController.swift
    
    import UIKit
    import SwiftyDropbox
    
    class ViewController: UIViewController {
    
    
    @IBAction func linkButtonPressed(sender: AnyObject) {
            if (Dropbox.authorizedClient == nil) {
                Dropbox.authorizeFromController(self)
            } else {
                print("User is already authorized!")
            }
    }
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
    
        // Verify user is logged into Dropbox
        if let client = Dropbox.authorizedClient {
    
            // Get the current user's account info
            client.users.getCurrentAccount().response { response, error in
                print("*** Get current account ***")
                if let account = response {
                    print("Hello \(account.name.givenName)!")
                } else {
                    print(error!)
                }
            }
    
            // List folder
            client.files.listFolder(path: "").response { response, error in
                print("*** List folder ***")
                if let result = response {
                    print("Folder contents:")
                    for entry in result.entries {
                        print(entry.name)
                    }
                } else {
                    print(error!)
                }
            }
    
            // Upload a file
            let fileData = "Hello!".dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: false)
            client.files.upload(path: "/hello.txt", body: fileData!).response { response, error in
                if let metadata = response {
                    print("*** Upload file ****")
                    print("Uploaded file name: \(metadata.name)")
                    print("Uploaded file revision: \(metadata.rev)")
    
                    // Get file (or folder) metadata
                    client.files.getMetadata(path: "/hello.txt").response { response, error in
                        print("*** Get file metadata ***")
                        if let metadata = response {
                            if let file = metadata as? Files.FileMetadata {
                                print("This is a file with path: \(file.pathLower)")
                                print("File size: \(file.size)")
                            } else if let folder = metadata as? Files.FolderMetadata {
                                print("This is a folder with path: \(folder.pathLower)")
                            }
                        } else {
                            print(error!)
                        }
                    }
    
                    // Download a file
    
                    let destination : (NSURL, NSHTTPURLResponse) -> NSURL = { temporaryURL, response in
                        let fileManager = NSFileManager.defaultManager()
                        let directoryURL = fileManager.URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask)[0]
                        // generate a unique name for this file in case we've seen it before
                        let UUID = NSUUID().UUIDString
                        let pathComponent = "\(UUID)-\(response.suggestedFilename!)"
                        return directoryURL.URLByAppendingPathComponent(pathComponent)
                    }
                    client.files.download(path: "/hello.txt", destination: destination).response { response, error in
                    //client.files.download(path: "/hello.txt").response { response, error in
                        if let (metadata, url) = response {
                            print("*** Download file ***")
                            let data = NSData(contentsOfURL: url)
                            print("Downloaded file name: \(metadata.name)")
                            print("Downloaded file url: \(url)")
                            print("Downloaded file data: \(data)")
                        } else {
                            print(error!)
                        }
                    }
    
                } else {
                    print(error!)
                }
            }
        }
    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    
    }