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.

Discuss Dropbox Developer & API

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

Re: backend Java process to read a shared folder

backend Java process to read a shared folder

novotny
Explorer | Level 4

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 test.auth short_live_token". This code appears to requires clicking a dropbox link

 

https://www.dropbox.com/oauth2/authorize?token_access_type=offline&response_type=code&client_id=XXXX...

 

to get an authorization code which is then used to generate a token and then the token can be used to list files in a folder. How can this all be done on the backend without human intervention? Are there any examples I can look at? With AWS S3 it's easily done with an access key and a secret key, I was hoping it would be similar.

 

Thanks, Jason

14 Replies 14

novotny
Explorer | 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

Greg-DB
Dropbox Staff

@novotny Yes, the expiration is only about the access token. The refresh token doesn't expire (though can be revoked on demand). If the expiration has passed, the client will use the refresh token to get a new access token automatically.

Здравко
Legendary | Level 20

Something more: don't try change 'expireAt'. Your code will fail!!! There are ways to optimize your code but you need to keep entire credentials object and serialize and deserialize it. Don't change anything by hands there.

novotny
Explorer | Level 4

Ok so just to confirm even if the hardcoded credential I pass in to create DBTeamClientV2 has expired already (i.e. I run this code next week), it will simply use the refresh token to obtain a new one and everything should work.

Здравко
Legendary | Level 20

Yes... 🙂

Need more support?