5

I am trying manipulate files using Dropbox Api by using DropNet Client (C# version of Dropbox CLient API). Here is my code:

    var client = new DropNetClient(APP_KEY,APP_SECRET);
    client.Delete("/Public/test.txt");

But it seems I need "USER TOKEN" and "USER SECRET" as well. Where should I get these two? Updated: I just need to manipulate files in my own folders and my shared folders. I already have APP_KEY and APP_SECRET from myApp page, where can I get "USER TOKEN" and "USER SECRET"

THanks

bryanmac
  • 38,941
  • 11
  • 91
  • 99
icn
  • 17,126
  • 39
  • 105
  • 141

3 Answers3

6

When you create your app on the dropbox web site, they give you an APP_KEY (identifies your app) and an APP_SECRET (like a password). You're essentially registering your app with drop box in order to integrate with their service.

Here's an overview: http://www.dropbox.com/developers/start/core

Click the "my apps" link in that page. You'll have to create or login with your drop box account. After that, you can create an app. Give it a name and description, select access folder or full contents and click OK. They will give you the key and secret after registering your app.

EDIT:

Concerning the specific C# DropNetClient, you're supposed to replace "APP_KEY" and "APP_SECRET" with your appKey and appSecret strings from that site.

This link lays out the sequence pretty clearly:

https://github.com/dkarzon/DropNet

_client = new DropNetClient("API KEY", "API SECRET");

for example:

// replace with given app key and secret from site
_client = new DropNetClient("8oz68cz267t52fz", "mavm58321hrhejy");

Once you have a client object, you need to pop a browser and have the user login to drop box with their user account. that's covered in step 2 of that link by getting the url.

var url = _client.BuildAuthorizeUrl();

Now that the user has logged on, you can get a user access token via synchronous or asynchronous methods. the user token enables a "remember me" feature without having the user reauthenticating and especially from your app storing their account/pass which you should never do. It's a token that proves they've authenticated with drop box. From step 3 of that link:

// Sync
var accessToken = _client.GetAccessToken(); //Store this token for "remember me" function

// Async
_client.GetAccessTokenAsync((accessToken) =>
    {
        //Store this token for "remember me" function
    },
    (error) =>
    {
        //Handle error
    });

Note that var accessToken is really a DropNet.Models.UserLogin object. That object contains:

    public string Token { get; set; }
    public string Secret { get; set; }
bryanmac
  • 38,941
  • 11
  • 91
  • 99
  • Please see my updates, I do have APP_KEY,APP_SECRET from myapp page but where can I get "USER TOKEN" and "USER SECRET"? – icn Dec 08 '11 at 00:40
  • I edited and answered your question. In the sample, those are place holder strings that you're supposed to replace with the key and secret strings give to you when you registered your app. – bryanmac Dec 08 '11 at 01:09
  • Thanks I understand these are APP_KEY and APP_SECRET. How can I get “USER TOKEN”, “USER SECRET” ? – icn Dec 08 '11 at 01:12
  • Thanks @bryanmac, is there a easy way to get "User Token"? all i need is to access my own dropbox, no other users' dropbox at all. I would like to update on my own dropbox using program/api on command line. I don't want to open a browser to input anything. – icn Dec 08 '11 at 03:05
  • The point is you authenticate once via there web gui, get a user token, store it and then you're app/commandline from that point on uses the token to access the service. That's the point of things like OAuth - you delegate to the service to authenticate, they give you a ticket and then you use it from then on ... – bryanmac Dec 08 '11 at 04:10
  • good work bryanmac, good to see some people using DropNet! I'm interested to see what you are using it for, drop me a tweet @d1k_is – dkarzon Jan 06 '12 at 01:18
  • Executing `var url = _client.BuildAuthorizeUrl();` is firing exception (ArgumentNullException ->. Value cannot be null. Parameter name: userLogin) – Junior Mayhé Nov 22 '12 at 10:50
  • how can you login for an existing user account? It only has `CreateAccount`. – John Woo Mar 18 '13 at 04:27
1

The user token/secret is what you get when a user gives your app access to their Dropbox via the browser-based authorization page, described here:

https://www.dropbox.com/developers/core/authentication

The Dropbox API is intended to link to each user's Dropbox. It sounds like you want it to link to your (developer-owned) Dropbox, which isn't currently supported. The only option would be to obtain a token via the auth flow in your deve environment, then somehow embed that token inside your app's code. Keeping that embedded token secret would be a challenge. Also, that embedded fixed token would be tied to your Dropbox account, and you'd have to be very careful never to unlink the app from your account (via https://www.dropbox.com/account#applications), which would invalidate the token.

Andrew
  • 1,073
  • 7
  • 6
1

There is a new way to get a token for your own account without going through all the OAuth stuff. On the Application settings page you will find a button "Generated access token". This generates a token for your own account.

Michiel Overeem
  • 3,894
  • 2
  • 27
  • 39