Java
Chilkat2 Java
Dropbox: Get Space Usage
See more Dropbox Examples
Demonstrates how to get the Dropbox space usage information for the current user's account.Chilkat Java Downloads
import com.chilkatsoft.chilkat2.ChilkatException;
import com.chilkatsoft.chilkat2.JsonObject;
import com.chilkatsoft.chilkat2.Rest;
public class ChilkatExample {
public static void main(String[] args) {
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
Rest rest = new Rest();
// Connect to the www.dropbox.com endpoint.
boolean bTls = true;
int port = 443;
boolean bAutoReconnect = true;
String responseStr;
try {
rest.connect("api.dropboxapi.com", port, bTls, bAutoReconnect);
rest.addHeader("Authorization", "Bearer DROPBOX-ACCESS-TOKEN");
responseStr = rest.fullRequestNoBody("POST", "/2/users/get_space_usage");
} catch (ChilkatException e) {
System.out.println(e.getLastErrorText());
return;
}
// Success is indicated by a 200 response status code.
if (rest.getResponseStatusCode() != 200) {
// Examine the request/response to see what happened.
System.out.println("response status code = " + rest.getResponseStatusCode());
System.out.println("response status text = " + rest.getResponseStatusText());
System.out.println("response header: " + rest.getResponseHeader());
System.out.println("response body (if any): " + responseStr);
System.out.println("---");
System.out.println("LastRequestStartLine: " + rest.getLastRequestStartLine());
System.out.println("LastRequestHeader: " + rest.getLastRequestHeader());
return;
}
JsonObject jsonResponse = new JsonObject();
jsonResponse.load(responseStr);
jsonResponse.setEmitCompact(false);
System.out.println(jsonResponse.emit());
// {
// "used": 3032115,
// "allocation": {
// ".tag": "individual",
// "allocated": 2147483648
// }
// }
//
}
}