DropNet DropBox login, how to do it programmatically in a console application?

Stefan Steiger picture Stefan Steiger · Jul 15, 2012 · Viewed 13.9k times · Source

Question:

I'm using a DropBox csharp API from here:
https://github.com/dkarzon/DropNet

From the Unit tests, and the only working sample from here https://github.com/dkarzon/DropNet/blob/master/DropNet.Samples/DropNet.Samples.Web/Default.aspx.cs

I figured that it works like this:

DropNet.DropNetClient client = new DropNet.DropNetClient(strApiKey, strAppSecret);

DropNet.Models.UserLogin login = client.GetToken();
client.UserLogin = login;

var accountInfo = client.AccountInfo();
str = accountInfo.quota_info.quota.ToString();

The probem is, it throws an exception on accountinfo. (System.Net.HttpStatusCode.Unauthorized) Everything before works fine, I get the login (usertoken & usersecret) .

I think my problem is this part of the sample application:

var url = _client.BuildAuthorizeUrl(Request.Url.ToString() + "?dropboxcallback=1");
Response.Redirect(url);

Where it redirects to dropbox for a login... I don't have a web application, so I have no URL...

What I have is a console application, that should make a backup of my database every evening automatically as a service, for which it certainly is very bad requiring a webbrowser and a user which has to type in email/username + password.

How can I do a login by directly supplying the hardcoded username and password ?

If I use the sample application, then it works, but that requires typing in the username and password on the web, and that sucks big time for a console application...

Answer

GameScripting picture GameScripting · Jul 15, 2012

As far as I know from other API's (facebook, google, stack exchange etc.) you'll have to redirect your user to a webpage of Dropbox, where it will grant permissions to you to use it's account to perform things.

So in general it is not possible to achive this without a webbrower. Otherwise you'll have to perform really dirty hacks to hack arround the permission system of dropbox.

Please have a look at "OAuth 2.0 authorization flow" on google. Here's a diagram I found at Yahoo which show's how it works:

The OAuth 2.0 flow