Question

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...

Was it helpful?

Solution 5

It is possible, using SharpBox - tested, works.
One needs to acquire the AccessToken as a one-time-action manually, then after that, one can omit the login page and use the saved AccessToken.

http://www.jayway.com/2012/02/06/unboxing-dropbox-and-sharpbox-2/

The magic line is:

Globals.DropBox.Token = AppLimit.CloudComputing.SharpBox.StorageProvider.DropBox.DropBoxStorageProviderTools
.ExchangeDropBoxRequestTokenIntoAccessToken(
      Globals.DropBox.config
    , Globals.DropBox.AppKey, Globals.DropBox.AppSec
    , Globals.DropBox.requestToken
);

OTHER TIPS

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

For uisng the DropnetClient's 4 argument constructor also we need to build web based url and allow the user to authenticate his account this is compusory thing, accesstoken will generate after the user hit allow button in authentication process

As GameScripting explained the Dropbox API uses oauth which requires user login through the dropbox website to authenticate the access tokens.

Checkout the documentation here: http://dkdevelopment.net/what-im-doing/dropnet/ for the 3 step process.

What sort of application are you building? Normal process is to load a browser control inside the application and navigate to the login URL with it.

Also have a look at the sample Windows Phone app to give you an idea of how this process works: https://github.com/dkarzon/DropNet/blob/master/DropNet.Samples/DropNet.Samples.WP7/MainPage.xaml.cs

Instead of hardcoding the username and password, you can hardcode the OAuth access token.

First, create a simple program (using the same app key) that follows the standard browser-based authorization flow. Then use it to authorize the app with the desired user. This will give you an OAuth access token (a "token" and "token secret") associated with that user and your app key.

Then, in your service-style application, just hardcode the OAuth access token (using DropNetClient's 4-argument constructor).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top