Overview

DropBox supports an OAuth mechanism, so you log in and get a token and a secret that you use with every call to sign the request. SharpDropBox Client for .NET automatically handles managing this information using IsolatedStorageSettings in WP7 (and the signing of your requests).

Api Setup

You need to have a DropBox Account and in the Developer area you need to create an application so you can get an AppKey and an AppSecret. Keep these handy you'll need them below.

Before Logging In

Before you log in you should check to make sure whether the user 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 
  if(dbxApp.NeedAuthInfo)
  {
    // Do Login
  }

Logging In

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    
    }
  });

Login Reset

If you need to remove the cached token/secret, simply do the following (so you can login as another user):
  dbxApp.Token = "";
  dbxApp.UserSecret = "";

Last edited Jan 18, 2011 at 7:55 PM by DevTheo, version 3

Comments

No comments yet.