We are aware of the issue with the badge emails resending to everyone, we apologise for the inconvenience - learn more here.
Forum Discussion
novotny
3 years agoExplorer | Level 4
backend Java process to read a shared folder
Hi,
We need a java workflow to scan the contents of a shared folder on a daily basis. I have downloaded the examples and looked at AuthorizeExample which I ran with the parameters "test.app tes...
novotny
Explorer | Level 4
Thanks, I am getting a little farther.
Regarding authorization, let me describe what I am doing:
1. I executed the Authorize example you pointed me to with the parameters "test.app test.auth short_live_token" such that my test.app contains my appKey and secretKey. It then produces the following:
1. Go to https://www.dropbox.com/oauth2/authorize?token_access_type=offline&response_type=code&client_id=XYZ
2. Click "Allow" (you might have to log in first).
3. Copy the authorization code.
Enter the authorization code here:
After step 1, I get my code and enter it. It now displays:
Authorization complete.
- User ID:
- Account ID: null
- Access Token: <ACCESS_TOKEN>
- Expires At: 1664569280436
- Refresh Token: <REFRESH_TOKEN>
- Scope: account_info.read contacts.read file_requests.read files.metadata.read members.read sharing.read team_data.content.read team_data.content.write team_data.governance.read team_data.governance.write team_data.member team_data.team_space team_info.read
Saved authorization information to "/Users/novotny/IdeaProjects/dropbox-sdk-java/test.auth"
2. In my own code I hardcode the values I received from the example and create a credential object which allows me to create a client
DbxCredential dbxCredential = new DbxCredential(ACCESS_TOKEN, EXPIRES_AT, REFRESH_TOKEN, APP_KEY, APP_SECRET);
DbxTeamClientV2 teamClientV2 = new DbxTeamClientV2(config, dbxCredential);
But now what? I see there is a refreshAccessToken API available, is this something that my backend process should execute once per day?
try {
DbxRefreshResult result = client.refreshAccessToken();
System.err.println(result);
} catch (DbxException e) {
throw new RuntimeException(e);
}
Thanks, Jason
Greg-DB
3 years agoDropbox Staff
novotny You can call refreshAccessToken if you want, but that is actually not necessary. The client will automatically handle this procedure for you whenever needed. (That is, it will automatically perform the refresh to get and use a new short-lived access token when the current one is expired, without you having to call any other methods yourself.)
- novotny3 years agoExplorer | Level 4
Ok thanks, so the code I have should work fine? However what happens when the app restarts and the original hardcoded credentials have expired already? (Since the EXPIRES_AT has been hardcoded) Will that still work?
- Здравко3 years agoLegendary | Level 20
It's related to access token only! Refresh token doesn't expire. 😉
- novotny3 years agoExplorer | Level 4
Let me make this clearer with code:
public DbxClientV2 createClient() throws DbxException {
DbxRequestConfig config = DbxRequestConfig.newBuilder("fingage").build();
DbxCredential dbxCredential = new DbxCredential(ACCESS_TOKEN, EXPIRES_AT, REFRESH_TOKEN, APP_KEY, APP_SECRET);
DbxTeamClientV2 teamClientV2 = new DbxTeamClientV2(config, dbxCredential);
PathRoot pathRoot = PathRoot.namespaceId("3103421521");
return teamClientV2.asMember("dbmid:AACV-hRckJZMB5ja-BpNuhN0PRjZod6__94").withPathRoot(pathRoot);
}It appears this code will work in creating DbxCredential since the EXPIRES_AT is in the future. However if I run this code in a few days, will it still work? Is it the case that if the supplied expiresAt is in the past will it still be able to refresh the credential? Or can I just provide a value for expiresAt that is far into the future?
Thanks again
About Discuss Dropbox Developer & API
Make connections with other developers
795 PostsLatest Activity: 8 days agoIf 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!