Click here to Skip to main content
12,759,231 members (33,309 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


15 bookmarked
Posted 28 Mar 2013

Simple one page RestSharp based console application for the DropBox Cloud service

, 28 Mar 2013 LGPL3
Rate this:
Please Sign up or sign in to vote.
The article describes how to use the RestSharp SDK to build an application for the DropBox Cloud service.


The present articles would be useful for developers who is going to the DropBox Cloud service for the desktop application and hesitating facing with number of available opportunities and already made contributions to the His Majesty WWW. If you, this article reader, are the one then the simple and easy to "copy and paste" code is waiting for you!


Now days the Cloud service is something everyone wants to use. It looks simple and fast to join to the popular Cloud Group. Particular Cloud service provider's Documentation pages usually contain plenty of information and due to the distributed nature of the Clouds often specify a custom REST style API. Such specification is well enough to understand number of features that the service provider offers but does not make us closer to the real implementation using any regular development tools and modern programming languages.

The RestSharp SDK offers plenty of already implemented features like OAuth v1 and OAuth v2 protocols, REST protocol, and many more and even provides us with a skeleton of the way how to use the RestSharp SDK in native style.

Before the application studying and usage please make sure that you have already passed the following steps: registering to the DropBox and creating a DropBox application (i.e. obtaining the App key/App secret pair). You can read instruction explaining these simple steps at the DropBox development resource here.

Using the code

The article provides you with the complete MS Visual Studio 2010 Express application that is able to get OAuth v1 Request token, the user approval, the Access token, and retrieve the user's account information as an regular sample of the DropBox service usage.

Let us go step by step through the most interesting parts of the application.

Configuring the application

Put the App key/App secret pair you have obtained to the constant string below. This is an important step and it is the only fragment of code that needs you contribution to make it actual and valid

private const string mc_apiKey = "YOUR_API_KEY";
private const string mc_appsecret = "YOUR_APP_SECRET";

Obtaining the Request Token

This step corresponds to the /oauth/request_token operation:

// Get request token

var baseUrl = "";

var client = new RestClient(baseUrl);
client.Authenticator = OAuth1Authenticator.ForRequestToken(mc_apiKey, mc_appsecret);
var request = new RestRequest(string.Format("/{0}/oauth/request_token", mc_version), Method.POST);

var response = client.Execute(request);

if (response.StatusCode != HttpStatusCode.OK)

OAuthToken requestToken = new OAuthToken();
    var qs = HttpUtility.ParseQueryString(response.Content);
    var oauth_token = qs["oauth_token"];
    var oauth_token_secret = qs["oauth_token_secret"];

    requestToken.Token = oauth_token;
    requestToken.Secret = oauth_token_secret;

Getting an approval from an user for the access

This step corresponds to the /oauth/authorize operation:

// Get approval from user for the access

// Create a HttpListener for the specified url.
string AuthorizationCallBackURL = string.Format(LoopbackCallback, 
  auth_GetRandomUnusedPort(), Assembly.GetEntryAssembly().GetName().Name);

request = new RestRequest(string.Format("/{0}/oauth/authorize", mc_version));
request.AddParameter("oauth_token", requestToken.Token);
request.AddParameter("oauth_callback", AuthorizationCallBackURL);
var url = client.BuildUri(request).ToString();

bool bUserAcceptedRequest = false;

var resetEvent = new ManualResetEvent(false);
using (var svr = SimpleServer.Create(AuthorizationCallBackURL, context =>
    string uid = context.Request.QueryString["uid"];
    string code = context.Request.QueryString["oauth_token"];

    if (!string.IsNullOrEmpty(uid) && !string.IsNullOrEmpty(code))
        bUserAcceptedRequest = true;




if (false == bUserAcceptedRequest)

Obtaining the Access Token

This step corresponds to the /oauth/access_token operation:

// Get access token

var verifier = "123456";
request = new RestRequest(string.Format("/{0}/oauth/access_token", mc_version), Method.POST);
client.Authenticator = OAuth1Authenticator.ForAccessToken(
mc_apiKey, mc_appsecret, requestToken.Token, requestToken.Secret, verifier
response = client.Execute(request);

if (response.StatusCode != HttpStatusCode.OK)

accessToken = new OAuthToken();
    var qs = HttpUtility.ParseQueryString(response.Content);
    var oauth_token = qs["oauth_token"];
    var oauth_token_secret = qs["oauth_token_secret"];

    accessToken.Token = oauth_token;
    accessToken.Secret = oauth_token_secret;

Obtaining the user Account Information

This step corresponds to the /account/info operation:

// Below is a sample how to access any DropBox service regular using the valid access token

request = new RestRequest(string.Format("/{0}/account/info", mc_version));
client.Authenticator = OAuth1Authenticator.ForProtectedResource(
mc_apiKey, mc_appsecret, accessToken.Token, accessToken.Secret

var responseAccount = client.Execute<AccountInfo>(request);

if (responseAccount.StatusCode != HttpStatusCode.OK)

AccountInfo acntInfo = responseAccount.Data;
if (null == acntInfo)

Console.WriteLine("First step tokens: token:{0} secret:{1}", requestToken.Token, requestToken.Secret);
Console.WriteLine("Second step tokens: token:{0} secret:{1}", accessToken.Token, accessToken.Secret);
Console.WriteLine("Account Info: {0}", responseAccount.Content);

Points of Interest

The main goal of the article is to equip a C# developer with complete reference application to speed up process of finding out with how it works, what to start with, and how to get it working

Let my small and modest contribution to help other developers who is looking for such aid.


I would like to tell good words regarding contributions that stand as a background for this article:


  • 2013-03-28: Initial revision.


This article, along with any associated source code and files, is licensed under The GNU Lesser General Public License (LGPLv3)


About the Author

Systems Engineer
Ukraine Ukraine
No Biography provided

You may also be interested in...


Comments and Discussions

QuestionSorry How to Upload file to Dropbox in MVC or with c# Pin
ebevictor16-Jun-15 6:00
memberebevictor16-Jun-15 6:00 
QuestionHow to Upload file to DropDown in MVC or with c# Pin
ebevictor16-Jun-15 5:48
memberebevictor16-Jun-15 5:48 
QuestionFile Upload process in c# Pin
Vivek Tewari9-Dec-13 1:38
memberVivek Tewari9-Dec-13 1:38 
AnswerRe: File Upload process in c# Pin
boris_oleinic9-Dec-13 8:39
professionalboris_oleinic9-Dec-13 8:39 
SuggestionCoding style Pin
Master.Man198012-Nov-13 5:02
memberMaster.Man198012-Nov-13 5:02 
AnswerRe: Coding style Pin
boris_oleinic12-Nov-13 5:25
professionalboris_oleinic12-Nov-13 5:25 
SuggestionRe: Coding style Pin
Master.Man198012-Nov-13 5:31
memberMaster.Man198012-Nov-13 5:31 
AnswerRe: Coding style Pin
boris_oleinic12-Nov-13 8:43
professionalboris_oleinic12-Nov-13 8:43 
SuggestionRe: Coding style Pin
Master.Man198012-Nov-13 9:12
memberMaster.Man198012-Nov-13 9:12 
AnswerRe: Coding style Pin
boris_oleinic12-Nov-13 11:42
professionalboris_oleinic12-Nov-13 11:42 
QuestionLinkedIn authentication? Pin
meraydin10-May-13 0:57
membermeraydin10-May-13 0:57 
AnswerRe: LinkedIn authentication? Pin
boris_oleinic11-May-13 23:51
professionalboris_oleinic11-May-13 23:51 
Question.Net Client Application Pin
Casperkamal4-Apr-13 9:47
memberCasperkamal4-Apr-13 9:47 
Hi Boris,

Thanks for this excellent article. I have a few questions. I'm a newbie to web and i'm a ERP Programmer of the VB6 Era. To me it all looks like taking a time machine and landing in this new world. Recently my company wants to extend the ERP to work with Cloud storage API's like Box/DropBox etc. After quite some struggle i learnt about PostMan and OAuth to test and understand the basics. The challenge now is that we must implement the OAuth process inside the ERP solution. We can reference C# applications so we can bring in a class library to implement the API reference using RestSharp. The problem is with Authentication, our's is like a basic WinForm application so we can add a browser client and then apply the url for the authorization process. It all becomes challenging when we wanted to capture the redirectURL and get the authroization code. If we are able to do that the rest can be managed. I tried several ways to implement the .Net browser control to capture the redirect URL but was futile. I saw that in your code you do a LoopbackCallback using SimpleServer, is this something that can be applied to WinForms and can it be applied to a enterprise level solution?

Your help will be very much appreciated.
Thanks in Advance.

AnswerRe: .Net Client Application Pin
boris_oleinic4-Apr-13 23:46
memberboris_oleinic4-Apr-13 23:46 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170217.1 | Last Updated 28 Mar 2013
Article Copyright 2013 by boris_oleinic
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid