Chapter 2. Dropbox API Binding

Spring.NET Social Dropbox offers integration with Dropbox's REST API through the IDropbox interface and its implementation, DropboxTemplate.

Creating an instance of DropboxTemplate involves invoking its constructor, passing in the application's OAuth credentials, an access token/secret pair authorizing the application to act on a user's behalf and the type of access level configured with the application.
For example:

string consumerKey = "..."; // The application's consumer key
string consumerSecret = "..."; // The application's consumer secret
string accessToken = "..."; // The access token granted after OAuth authorization
string accessTokenSecret = "..."; // The access token secret granted after OAuth authorization
IDropbox dropbox = new DropboxTemplate(consumerKey, consumerSecret, accessToken, accessTokenSecret, AccessLevel.Full);

In addition, DropboxTemplate has a Locale property that allows to specify language settings of content responses:

dropbox.Locale = "fr-FR";

You can also get an instance of IDropbox from the DropboxServiceProvider class.
The example code below shows use of the DropboxServiceProvider to retrieve an instance of IDropbox after authenticating through OAuth1 server-side flow:

DropboxServiceProvider serviceProvider = new DropboxServiceProvider("consumerKey", "consumerSecret", AccessLevel.AppFolder);
OAuth1Operations oauthOperations = serviceProvider.AuthOperations;
OAuthToken requestToken = oauthOperations.FetchRequestToken(null, null);
OAuth1Parameters parameters = new OAuth1Parameters();
parameters.CallbackUrl = "http://my-callback-url/";
parameters.Add("locale", "fr-FR"); // for a localized version of the authorization website
string authorizeUrl = oauthOperations.BuildAuthorizeUrl(requestToken, parameters);
Response.Redirect(authorizeUrl);

// upon receiving the callback from the provider:
OAuthToken accessToken = oauthOperations.ExchangeForAccessToken(new AuthorizedRequestToken(requestToken, null), null);
IDropbox dropboxApi = serviceProvider.GetApi(accessToken.Value, accessToken.Secret);

Once you have a IDropbox, you can perform a several operations against Dropbox.
IDropbox is defined as follows:

public interface IDropbox : IApiBinding
{
  DropboxProfile GetUserProfile();

  Entry CreateFolder(string path);

  Entry Delete(string path);

  Entry Move(string fromPath, string toPath);

  FileRef CreateFileRef(string path);
  
  Entry Copy(string fromPath, string toPath);
  
  Entry CopyFileRef(string fromFileRef, string toPath);

  Entry UploadFile(IResource file, string path);

  Entry UploadFile(IResource file, string path, bool overwrite, string revision);

  DropboxFile DownloadFile(string path);

  DropboxFile DownloadFile(string path, string revision);

  DropboxFile DownloadPartialFile(string path, long startOffset, long length);

  DropboxFile DownloadPartialFile(string path, long startOffset, long length, string revision);

  DeltaPage Delta(string cursor);

  Entry GetMetadata(string path);

  Entry GetMetadata(string path, MetadataParameters parameters);

  IList<Entry> GetRevisions(string path);

  IList<Entry> GetRevisions(string path, int revLimit);

  Entry Restore(string path, string revision);

  IList<Entry> Search(string path, string query);

  IList<Entry> Search(string path, string query, int fileLimit, bool includeDeleted);

  DropboxLink GetShareableLink(string path);

  DropboxLink GetMediaLink(string path);

  DropboxFile DownloadThumbnail(string path, ThumbnailFormat format, ThumbnailSize size);
}

There are 3 ways to call a method depending on the target Framework:

For complete details on the Spring.NET Social's entire Dropbox API binding, refer to the API documentation from the "doc/api" directory of the distribution and to the Dropbox REST API documentation.
Samples are provided in the 'examples' directory of the distribution.