title | layout |
---|---|
DropNetRT |
layout |
DropNetRT is a Portable Class Library for .Net (including Windows Store and Windows Phone) applications to connect to the Dropbox API.
PM> Install-Package DropNetRT
To create an app that uses Dropbox you first need to register your app with Dropbox (Developer site). This will give you the API Key and Secret combination required to use the API.
Once you have your API Key and Secret download DropNetRT from NuGet (or alternatively download the source from GitHub).
To start using DropNetRT create an instance of the DropNetClient class using your API Key and Secret generated from the Dropbox developer site.
{% highlight csharp %}var client = new DropNetClient("API KEY", "API SECRET");{% endhighlight %}The constructor has an overload method for if you have already authenticated with the API and have an access token for the user. (covered in Authentication).
{% highlight csharp %}var client = new DropNetClient("API KEY", "API SECRET", "USER TOKEN", "USER SECRET");{% endhighlight %}The dropbox API uses oauth for authenticating, it does both v1 and v2 but at the moment DropNetRT only supports oauth v1.
Authentication is a 3 step process.
- Step 1: Get a request token from the API.
- Step 2: Navigate the user to the dropbox site to login (using the request token).
- Step 3: Convert the request token into an access token to use the rest of the API.
Step 1: Get a request token from the API. Call the GetRequestToken function to create a new request token. Note: The DropNetClient instance will save this as the UserLogin property but is also returned by the function.
{% highlight csharp %}var requestToken = await client.GetRequestToken();{% endhighlight %}Step 2: Navigate the user to the dropbox site to login (using the request token).
{% highlight csharp %}var url = client.BuildAuthorizeUrl(requestToken, "http://dkdevelopment.net");{% endhighlight %}From here you will need to open a browser with the url given to allow the user to login. Then wait for the callback the the given callback url before moving on. An example of this step can be found in the WP8 sample app (source on github). WinRT apps can use the WebAuthenticationBroker for this, just give it the url and callback parameters then parse the response for the token querystring parameter. (Note the secret doesn't change, only the token)
Step 3: Convert the request token into an access token to use the rest of the API. To do this call the GetAccessToken function. Note: The DropNetClient instance will save this as the UserLogin property but is also returned by the function. Save this token so the user doesn't have to reauthenticate each time.
{% highlight csharp %}var accessToken = await client.GetAccessToken();{% endhighlight %}To set the DropNetClient to use an app folder instead of the users full dropbox folder set the UseSandbox property to true. This may cause the client to throw exceptions if the app is set to only be allowed access to app folders.
{% highlight csharp %}client.UseSandbox = true;{% endhighlight %}coming soon
Copy
Copies a file or folder from one location to another.
Create Folder
Creates an empty folder with the given path
Delete
Deletes a file or folder given its path
Get Delta
Gets the Delta (changes) of a given path and cursor from the last time it was called (otherwise returns last 2000 folder changes)
Get File
Gets a file from dropbox given the path
GetMetaData
Gets info on a file or folder (including folder contents). There are a few functions for getting an items Metadata, most of them are shorthand methods of the main one: GetMetaData(string path, string hash, int? rev, bool list, bool includeDeleted)
GetShare
Gets a share link for a file or folder.
Search
Searches for a given string.
DropNetRT is a PCL (Portable Class Library) which means the same dll can be used across multiple platforms. Here are the target frameworks:
- .NET 4.5
- .NET for Windows Store apps (WinRT)
- Windows Phone 7.5 and higher
- Silverlight 4 and higher
coming soon
If you have any questions about DropNet post a question on Stack Overflow - http://stackoverflow.com/questions/tagged/dropnet