简体   繁体   中英

Global cursor in Dropbox API v2

I use dropbox /delta endpoint to track changes inside Dropbox. More precisely, the following piece of code allow me to track changes in "/superfolder" recursively (I'm using here DbxClientV1):

    List<String> listOfResults = new ArrayList<String>();
    String path = "/superfolder";
    String cursor = null;

    while (true) {
        DbxDelta<DbxEntry> deltaWithPathPrefix = client.getDeltaWithPathPrefix(cursor, path);
        cursor = deltaWithPathPrefix.cursor;
        if (deltaWithPathPrefix.reset) {
            System.out.println("Reset!");
        }
        for (DbxDelta.Entry entry : deltaWithPathPrefix.entries) {
            if (entry.metadata == null) {
                System.out.println("Deleted: " + entry.lcPath);
                listOfResults.add(entry.lcPath);
            } else {
                System.out.println("Added or modified: " + entry.lcPath);

            }
        }

        if (!deltaWithPathPrefix.hasMore) {
            try {
                Thread.sleep(1000);
            } catch (InterruptedException ex) {
                Logger.getLogger(MainSearchV1.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }

Now, I've switched to DbxClientV2 client. To track changes on dropbox I use client.files.listFolder() in the following form:

    TreeMap<String, Metadata> children = new TreeMap<String, Metadata>();
    Files.ListFolderResult result;

    String cursor = null;

    while (true) {
        if (cursor == null) {
            result = client.files.listFolder("/superfolder");
        } else {
            result = client.files.listFolderContinue(cursor);
        }
        cursor = result.cursor;
        for (Metadata md : result.entries) {
            if (md instanceof DeletedMetadata) {
                children.remove(md.pathLower);
                System.out.println("Deleted: " + md.pathLower);
            } else {
                children.put(md.pathLower, md);
                System.out.println("State: " + md.pathLower);
                System.out.println(md.toString());
            }
        }

        if (!result.hasMore) {
            try {
                Thread.sleep(1000);
            } catch (InterruptedException ex) {
            }
        }
    }

Regretably, I've discovered that I can only track changes only of "superfolder" folder. Is there a way to get a "global cursor" that tracks changes recursively in Dropbox API v2?

The Java SDK uses the builder pattern for pretty much all calls with multiple optional arguments. If I understand your question correctly, I think you're looking for this:

result = client.files.listFolderBuilder("/superfolder")
               .recursive(true)
               .start();

EDIT : You asked about a "global" cursor. I think you actually meant recursive, but in case you really meant global, you can pass an empty string ( "" ) as a path to represent the root.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM