You might see that the Dropbox Community team have been busy working on some major updates to the Community itself! So, here is some info on what’s changed, what’s staying the same and what you can expect from the Dropbox Community overall.
Forum Discussion
Garnik G.
10 years agoExplorer | Level 4
How to get files by DropBoxRest API in C#
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
- 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 likeAuthorizeAsync
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-DBDropbox Staff
[Cross-linking for reference: https://stackoverflow.com/questions/28833004/how-to-get-dropbox-files-by-dropboxrest-api-in-c ]
- 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 questionHere 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 ? - Steve M.Dropbox Staff
You could do this, but I would advise against it. Dropbox isn't designed for this kind of account sharing, and anyone who had access to your app would be able to extract the access token and take control of the account (e.g. delete all the files).
About Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.5,917 PostsLatest Activity: 2 hours ago
If you need more help you can view your support options (expected response time for an email or ticket is 24 hours), or contact us on X or Facebook.
For more info on available support options for your Dropbox plan, see this article.
If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!