adam adam - 3 months ago 11
Java Question

Dropbox API Cursors: how long are they valid for and using them properly over time

I've been testing the list files API (still using a development account, maybe that's part of the problem?), but seeing unexpected results. Basically, I ask info on a path, process the results, and then ask for a "new" cursor via "listFolderGetLatestCursor" but it says there are no changes. Am I missing something?

Question: How long is a cursor valid for?

Problem: If I run the following method with a

null
cursor in path
/tmp
and set aside the cursor as
cursor1
and then modify files in
/tmp
and then run the same method with
cursor1
after 1 day, getting back
cursor2
it doesn't show any changes. Sometimes, I seem to get expected results when I run it in shorter time-intervals, but I must be missing something.

public String doDropboxWork(String path, String cursor) {
// make request for path
if (cursor == null) {
ListFolderBuilder listFolderBuilder = client.files().listFolderBuilder(path);
result = listFolderBuilder.withRecursive(true).withIncludeDeleted(false).start();
} else {
result = client.files().listFolderContinue(cursor);
}

while (true) {
// ... do work ....
if (!result.getHasMore()) {
break;
}
result = client.files().listFolderContinue(result.getCursor());
}

// get new cursor
String cursor2 = client.files().listFolderGetLatestCursor(path).getCursor();
return cursor2;
}


thanks in advance

Answer

based on feedback from the Dropbox Forum, the fix is to not ask for a new cursor:

eg:
//String cursor2 = client.files().listFolderGetLatestCursor(path).getCursor();

as this resets the polling