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.

Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

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

Java example to find recent updates (without having to poll) using webhook notification

Java example to find recent updates (without having to poll) using webhook notification

sl4677
Explorer | Level 3

Do you have an example in Java that selects recent adds/deletes to a dropbox folder do doesn't require polling?

 

The examples that I pulled from Github do contain one that uses a loop that continuously polls to find recent updates. I have written a solution using webhooks. I would prefer not to have to poll whether in a separate thread or not. I have used the  ListFolderGetLatestCursorBuilder and ListFolderGetLatestCursorResult, followed by issuing a DbxClientV2.files.listFolderContinue() without success.  I find that ListFolderGetLatestCursorResult initially returns all entries regardless of whether they are recently changed or not. 

 

The only way I see to pick out the recent updates is to use the FileMetaData.getClientModified to get the timestamp of when the file was added. I see that the API warns against using it for this purpose, but I see no other recourse at this time, without having to poll.

 

 

4 Replies 4

Greg-DB
Dropbox Staff

I don't believe we have any examples quite like that for the API v2 Java SDK, but I'll be happy to help with any issues you're running in to.

 

The basic idea is that you can call listFolder and listFolderContinue initially until hasMore is false to get the initial state. Then, you can listFolderContinue for the relevant user when you get a webhook notification for them. At each call, you should re-use the latest cursor you had for that user, and then store the new one. That lets you retrieve only the new entries.

 

There's more information on processing these in the documentation here:

 

https://dropbox.github.io/dropbox-sdk-java/api-docs/v2.1.x/com/dropbox/core/v2/files/DbxUserFilesReq...

 

When using webhooks, you would trigger the subseqeuent listFolderContinue calls from your webhook URI handler, (as opposed to a long poll loop). There are some best practices covered here:

 

https://www.dropbox.com/developers/reference/webhooks

 

If you're having any trouble with any particular methods, please share the details (the code you're using, any errors you're getting, etc.) and I'll take a look.

sl4677
Explorer | Level 3
Thanks for your prompt response Greg.
I'll be discussing this with my team lead and will get back to you -- likely sometime next week.
Thanks once again for the helpful information.
Sam

sl4677
Explorer | Level 3

Hi Greg -- 

TheAPI  documentation you mentioned at https://dropbox.github.io/dropbox-sdk-java/api-docs/v2.1.x/com/dropbox/core/v2/files/DbxUserFilesReq...   

suggests using ListFolderArg.getRecursive() to keep a local cache of the Dropbox metadata state (e.g. the latest cursor for a user) to be able to find the latest file changes when a user send a Webhook notification. It appears that ListFolderArg was available in version 2.0, but is no longer documented or used in v2.1 .

 

Using version 2.1, what do you then recommend that I use to store the state locally, to be able to find recent file updates for a user with a Webhook notification?

 

Thanks,

Sam

Greg-DB
Dropbox Staff

Thanks for pointing that out! It looks like the documentation needs to be updated. 

 

You can use the builder to build this call with the desired options, like this:

 

ListFolderResult result = client.files().listFolderBuilder("").withRecursive(true).start();
Need more support?
Who's talking

Top contributors to this post

  • User avatar
    Greg-DB Dropbox Staff
  • User avatar
    sl4677 Explorer | Level 3
What do Dropbox user levels mean?