Your workflow is unique 👨💻 - tell us how you use Dropbox here.
Forum Discussion
thorty
8 years agoExplorer | Level 3
OAuth2 one token for differet interfaces
Hello, with APIv1 I have build an App wich runs in java on different machines. The App is linked with a speacial dropbox folder so that the app hase the same file basis on every machine. How ...
Greg-DB
Dropbox Community Moderator
8 years agoAPI v1 and API v2 should work the same way in this regard. You can use the same OAuth 2 access token from multiple instances of the same app, or you can create and use multiple different access tokens. Creating additional access tokens does not invalidate previous access tokens.
If something isn't working as expected, please share a sample request and unexpected response. (Be sure to redact the access token itself though.)
If something isn't working as expected, please share a sample request and unexpected response. (Be sure to redact the access token itself though.)
- thorty8 years agoExplorer | Level 3
Thanks Greg,
"or you can create and use multiple different access tokens" - that would be great!
I use the Java API SDK. Can you tell my how I can get an existing token or generate an additional token? Whenever I creat a "new" token the older token does not working anymore and an "invalid access token" exception is thrown.
This is my code to generate a new token:
public static String doAuth() { // Only display important log messages. Logger.getLogger("").setLevel(Level.WARNING); // Read app info file (contains app key and app secret) DbxAppInfo appInfo; appInfo = new DbxAppInfo(APP_KEY, APP_SECRET); // Run through Dropbox API authorization process DbxRequestConfig requestConfig = new DbxRequestConfig("foo"); DbxWebAuth webAuth = new DbxWebAuth(requestConfig, appInfo); DbxWebAuth.Request webAuthRequest = DbxWebAuth.newRequestBuilder() .withNoRedirect() .withForceReapprove(Boolean.FALSE) .build(); String authorizeUrl = webAuth.authorize(webAuthRequest); System.out.println("1. Go to " + authorizeUrl); System.out.println("2. Click \"Allow\" (you might have to log in first)."); System.out.println("3. Copy the authorization code."); System.out.print("Enter the authorization code here: "); String code = null; try { code = new BufferedReader(new InputStreamReader(System.in)).readLine(); } catch (IOException ex) { Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); } if (code == null) { System.exit(1); return null; } code = code.trim(); DbxAuthFinish authFinish; try { authFinish = webAuth.finishFromCode(code); } catch (DbxException ex) { System.err.println("Error in DbxWebAuth.authorize: " + ex.getMessage()); System.exit(1); return null; } System.out.println("Authorization complete."); System.out.println("- User ID: " + authFinish.getUserId()); System.out.println("- Access Token: " + authFinish.getAccessToken()); // Save auth information to output file. DbxAuthInfo authInfo = new DbxAuthInfo(authFinish.getAccessToken(), appInfo.getHost()); File output = new File("token"); try { DbxAuthInfo.Writer.writeToFile(authInfo, output); System.out.println("Saved authorization information to \"" + output.getCanonicalPath() + "\"."); } catch (IOException ex) { System.err.println("Error saving to <auth-file-out>: " + ex.getMessage()); System.err.println("Dumping to stderr instead:"); try { DbxAuthInfo.Writer.writeToStream(authInfo, System.err); } catch (IOException ex1) { Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex1); } } return authFinish.getAccessToken(); }- Greg-DB8 years ago
Dropbox Community Moderator
thorty Using the DbxWebAuth flow you have is a valid way to get another access token, and that shouldn't revoke any previous tokens
Can you elaborate on the issue you're having with the previous token? E.g., please share the code and full output.
Make sure you're not mixing up the "authorization code" and "access token". The authorization code is single-use only, and can exchanged for an access token once. The resulting access token can be stored and re-used.
There are other ways tokens can be revoked too, so make sure you're not accidentally doing any of the following:
- by the user unlinking the app via their account security page: https://www.dropbox.com/account/security
- by deleting the app folder, if the app uses the app folder permission
- by the app revoking the access token via the tokenRevoke method: https://dropbox.github.io/dropbox-sdk-java/api-docs/v3.0.x/com/dropbox/core/v2/auth/DbxUserAuthRequests.html#tokenRevoke--
- by disabling the user account
- by disabling the API app
- by disabling the app owner's account
About Dropbox API Support and Feedback
Get help with the Dropbox API from fellow developers and experts.
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!