This topic will give you a quick overview of using the API (much of the examples come directly from the DropBoxAuthSimple example).

Logging in

Before you log in you should check to make sure whether the uiser hasn't already logged in. If they have then the app will automatically have cached the User secret which is what is needed to access the API. To do this You can do the following:

  var dbxApp = new DropBoxApp("ApiKey", "ApiSecret");  // Should be in a variable which is accessible Application-wide 
    // Do Login

If you need to login on behalf of the user, prompt the user for their credentials (and don't save them, we'll cache the User Token/Secret for you) then do the following:
  dbxApp.LoginAndGetAuthCredentials(testEMail, testAccountPwd, (success, ex) =>
    if (success)
      // We are now logged in and the User Token/Secret are now cached.
      // "dbxApp.Token" contains the user token (so you could set it to an empty string to force re-logging in
      // "dbxApp.UserSecret" contains the user token (so you could set it to an empty string to force re-logging in    

To get the root directory (or any other Directory), do this:
  // You can provide any of the DropBoc Parameters in your call (in this example we are passing "list=true" which means we want to get the contents of the directory
  // That first value is the path you want to look at (you can look at 1 subdirectory at a time
  dbApp.ListDirContexts("", (new[] { "list=true" }).ToList(), (obj) =>
    if (obj.Error != null)
        // obj.Error is the exception we got (the InnerException is the actual one coming back from the API -- if there was one.. it might be an error from DropBox)
        // The obj param coming from the callback has the following additional properties:
        //   Path - The Original Path that you called the routine with
        //   Cached - Indicates that nothing changed since the last time you looked at this path (so the result was built based on the cache).. the last return might have happened 3 sessions ago
        //   Dictionary - This contains the name/values pairs coming back in the JSON returned by the service (useful if there is something you want to look at and tweak
        //   DirInfo - This contains information about the path and includes the contents of the directory

To get a file:

Last edited Dec 17, 2010 at 2:07 AM by DevTheo, version 3


No comments yet.