cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Want to learn some quick and useful tips to make your day easier? Check out how Calvin uses Replay to get feedback from other teams at Dropbox here.

Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to get files by DropBoxRest API in C#

How to get files by DropBoxRest API in C#

Garnik G.
Explorer | Level 4

Hi

My goal is to get files by DropBoxRest API in C#
Here is my code

var options = new Options
    {
        ClientId = "", //App key
        ClientSecret = "", //App secret
        RedirectUri = "https://www.dropbox.com/1/oauth2/authorize"
    };

// Initialize a new Client (without an AccessToken)
var client = new Client(options);

// Get the OAuth Request Url
var authRequestUrl = await client.Core.OAuth2.AuthorizeAsync(access_token which generated in my account);

// TODO: Navigate to authRequestUrl using the browser, and retrieve the Authorization Code from the response
var authCode = ""; Which code have to be here ???

// Exchange the Authorization Code with Access/Refresh tokens
var token = await client.Core.OAuth2.TokenAsync(authCode); in this line occured the following error
  //An unhandled exception of type 'System.AggregateException' occurred in mscorlib.dll      

// Get account info
var accountInfo = await client.Core.Accounts.AccountInfoAsync();

Please give me an advice

19 Replies 19

Steve M.
Dropbox Staff

It looks like you're using this library: https://github.com/saguiitay/DropboxRestAPI.

You might consider asking the author for help.

The "authorization code" is generally what gets displayed when you browse to https://www.dropbox.com/1/oauth2/authorize?response_type=code&client_id=<YOUR-APP-KEY>. It looks like AuthorizeAsync returns that kind of URL, so you should then browse to the URL, get the authorization code displayed there, and use it in the next step. (You'd have to prompt the user somehow to enter the authorization code before proceeding.)

This code looks like it might be useful for a command-line app? With a web app, you would use redirects to move the user through the OAuth process (e.g. https://github.com/smarx/othw/tree/master/C%23), and for a desktop app, you would probably display an embedded browser in the app (e.g. https://blogs.dropbox.com/developers/2014/04/dropbox-authorization-in-a-windows-store-app/).

Greg-DB
Dropbox Staff

Garnik G.
Explorer | Level 4

There are many libraries in your site for working with DropBox data
My goal is to read dropbox .txt files
Which is the best way to do that ?

Steve M.
Dropbox Staff

Any of the SDKs (ours or third-parties) should be able to read text files from Dropbox.

Garnik G.
Explorer | Level 4

Now I'm using the following topic
http://www.b4x.com/android/forum/threads/dropbox-oauth-2-tutorial.19503/
It's helpful and I can get information from DropBox but there is a question

Here we need to do a step by hand

var authorizeUrl = "https://www.dropbox.com/1/oauth/authorize?" + queryString;
Process.Start(authorizeUrl);

In above code we have to open browser and click to allow in order can go to the next step.
I don't think that's user friendly. Is there a way to do it without opening the browser.

Steve M.
Dropbox Staff

A user has to grant your application permission before it can access that user's Dropbox. There's no way to do that without the user interacting with dropbox.com (or the Dropbox app on mobile).

But once a user has authorized your app once, they never need to do it again.

Garnik G.
Explorer | Level 4

Thank you for the answer.
Out project is a desktop application so many users should use the software.
If I get the access_token and Secret can we use it always ? or we need to update access_token after some time ?
Is it right to get access_token and set as static value in code in order software always can use that value for getting an information ?

Steve M.
Dropbox Staff

Once a user has authorized your app (the first time they use it), you should keep reusing the same access token from then on. But you can't hardcode the access token in the app, because it will be different for each user.

Garnik G.
Explorer | Level 4

Thank you for the answer.
We want to use DropBox as database. All programs should use the same files. So we are going to have a dropbox account and get info from a few softwares. So I think in that case we can hardcode the token, right ?

Need more support?
Who's talking

Top contributors to this post

  • User avatar
    Steve M. Dropbox Staff
  • User avatar
    Velmurugan N. New member | Level 1
  • User avatar
    Garnik G. Explorer | Level 4
What do Dropbox user levels mean?