Click here to Skip to main content
13,094,001 members (56,220 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
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 5:00
memberebevictor16-Jun-15 5:00 
QuestionHow to Upload file to DropDown in MVC or with c# Pin
ebevictor16-Jun-15 4:48
memberebevictor16-Jun-15 4:48 
QuestionFile Upload process in c# Pin
Vivek Tewari9-Dec-13 0:38
memberVivek Tewari9-Dec-13 0:38 
AnswerRe: File Upload process in c# Pin
boris_oleinic9-Dec-13 7:39
professionalboris_oleinic9-Dec-13 7:39 
SuggestionCoding style Pin
Master.Man198012-Nov-13 4:02
memberMaster.Man198012-Nov-13 4:02 
AnswerRe: Coding style Pin
boris_oleinic12-Nov-13 4:25
professionalboris_oleinic12-Nov-13 4:25 
SuggestionRe: Coding style Pin
Master.Man198012-Nov-13 4:31
memberMaster.Man198012-Nov-13 4:31 
AnswerRe: Coding style Pin
boris_oleinic12-Nov-13 7:43
professionalboris_oleinic12-Nov-13 7:43 
SuggestionRe: Coding style Pin
Master.Man198012-Nov-13 8:12
memberMaster.Man198012-Nov-13 8:12 
AnswerRe: Coding style Pin
boris_oleinic12-Nov-13 10:42
professionalboris_oleinic12-Nov-13 10:42 
QuestionLinkedIn authentication? Pin
meraydin9-May-13 23:57
membermeraydin9-May-13 23:57 
AnswerRe: LinkedIn authentication? Pin
boris_oleinic11-May-13 22:51
professionalboris_oleinic11-May-13 22:51 
Question.Net Client Application Pin
Casperkamal4-Apr-13 8:47
memberCasperkamal4-Apr-13 8:47 
AnswerRe: .Net Client Application Pin
boris_oleinic4-Apr-13 22:46
memberboris_oleinic4-Apr-13 22: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.170813.1 | Last Updated 28 Mar 2013
Article Copyright 2013 by boris_oleinic
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid