Need to see if your shared folder is taking up space on your dropbox 👨💻? Find out how to check here.
Forum Discussion
Peter K.23
11 years agoNew member | Level 1
Auto authorize with Java client or Mule ESB component
Is there anyway to provide authorization automatically ? The usefulness of providing an API to interact with the data store in Dropbox and requiring a manual authorization is zero.
7 Replies
Replies have been turned off for this discussion
- Steve M.11 years ago
Dropbox Staff
What exactly do you mean by "provide authorization automatically?" You certainly can't access a user's Dropbox without that user's permission.
The Dropbox API uses OAuth to get a user's permission. Once the user has authorized your app, you can access their Dropbox. Each user of your app should only need to authorize the app once.
- Peter K.2311 years agoNew member | Level 1
So that clarifies things a bit. The issue is that it is my drop box and I wanted API access to it. I was not sure if I had to CONTINUOUSLY allow (which made no sense) and thus it would be crazy to go that route.
Once I approve access and to that app, then it would work onwards and that makes more sense. However, executing against a Java client is currently the issue, as I have yet to find a good example that automatically retrieves the auth code such as through an HTTP client and avoid manual interaction from the auth point (after auth is provided from the web console).
- Steve M.11 years ago
Dropbox Staff
The tutorial shows how to go through the auth flow in a command-line app (https://www.dropbox.com/developers/core/start/java), and as it says, you can just store the access token for future use:
The access token is all you'll need to make API requests on behalf of this user, so you should store it away for safe-keeping (even though we don't for this tutorial). By storing the access token, you won't need to go through these steps again unless the user reinstalls your app or revokes access via the Dropbox website.
If you just need an access token for your own account—no other user will use your app—you can generate an access token directly from the app console: https://blogs.dropbox.com/developers/2014/05/generate-an-access-token-for-your-own-account/.
- Peter K.2311 years agoNew member | Level 1
I did use that example and stored the code from the dropbox site into the app and ran it again:
// String code = new BufferedReader(new InputStreamReader(System.in)).readLine().trim();
String code = "cQNNj44-oxgAAAAAAAAJWMnVOFCIlA4xqXbrz56BZPY";On the 2nd run, it stated:
Exception in thread "main" com.dropbox.core.DbxException$BadRequest: {"error_description": "code has already been used", "error": "invalid_grant"}
Thus, you can't use the code again ?
- Steve M.11 years ago
Dropbox Staff
The exception is correct... you're trying to reuse an authorization code that's already been used. An authorization code can only be used once (and within a limited time period).
What you need to do is reuse the access token.
Once you have an access token, your code can just be this:
DbxClient client = new DbxClient(config, "<YOUR ACCESS TOKEN HERE>"); - Peter K.2311 years agoNew member | Level 1
Updated the test client as you showed:
DbxClient client = new DbxClient(config, "<YOUR ACCESS TOKEN HERE>");
and it worked. But, you stated:
"An authorization code can only be used once (and within a limited time period)." .... does that mean that this auth code will become invalidated in the future ?
- Steve M.11 years ago
Dropbox Staff
"Authorization code" and "access token" are two different things.
You were trying to reuse an authorization code, which won't work.
Now you're reusing an access token, which will work. (Access tokens are meant to be reused indefinitely.)
About Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.
The Dropbox Community team is active from Monday to Friday. We try to respond to you as soon as we can, usually within 2 hours.
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, Facebook or Instagram.
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!