Skip to content

Instantly share code, notes, and snippets.

@FlorianWendel
Created January 11, 2017 15:00
Show Gist options
  • Save FlorianWendel/0aef0008d60d8032729833bfa807cf0b to your computer and use it in GitHub Desktop.
Save FlorianWendel/0aef0008d60d8032729833bfa807cf0b to your computer and use it in GitHub Desktop.
// Initialize like usual
CloudRail.setAppKey([CloudRail key]);
Dropbox dropbox = new Dropbox([Credentials etc.]);
// Specify the URL of the Dropbox API endpoint, the base URL is prepended by default
AdvancedRequestSpecification req = new AdvancedRequestSpecification("/sharing/list_folders");
// Set the HTTP request method to POST
req.setMethod("POST");
// Specify the body and let it be converted to JSON
Map<String, Object> body = new HashMap<String, Object>();
body.put("limit", 100);
req.setBodyStringifyJson(body);
// Specify the headers
Map<String, String> headers = new HashMap<String, String>();
headers.put("Content-Type", "application/json");
req.setHeaders(headers);
// Execute the request, CloudRail will start the authentication flow if necessary
// and append the authorization header.
// The response is checked for errors.
AdvancedRequestResponse res = dropbox.advancedRequest(req);
// Extract the parsed response body
Map<String, Object> parsed = (Map<String, Object>) res.getBodyJsonParsed();
// Now you can work with the answer
List<Map<String, Object>> entries = (List<Map<String, Object>>) parsed.get("entries");
Log.i("info", "We have " + entries.size() + " shared folders");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment