Sample code for 30+ languages & platforms
Dart

Dropbox: Get Space Usage

See more Dropbox Examples

Demonstrates how to get the Dropbox space usage information for the current user's account.

Chilkat Dart Downloads

Dart
import 'package:chilkat/chilkat.dart';

void main() {
  // This example requires the Chilkat API to have been previously unlocked.
  // See Global Unlock Sample for sample code.

  final rest = CkRest();

  // Connect to the www.dropbox.com endpoint.
  final bTls = true;
  final port = 443;
  final bAutoReconnect = true;
  try {
    rest.connect('api.dropboxapi.com', port, bTls, bAutoReconnect);
  } on ChilkatException catch (e) {
    print(e.lastErrorText);
    return;
  }

  rest.addHeader('Authorization', 'Bearer DROPBOX-ACCESS-TOKEN');

  final String responseStr;
  try {
    responseStr = rest.fullRequestNoBody('POST', '/2/users/get_space_usage');
  } on ChilkatException catch (e) {
    print(e.lastErrorText);
    return;
  }

  // Success is indicated by a 200 response status code.
  if (rest.responseStatusCode != 200) {
    // Examine the request/response to see what happened.
    print('response status code = ${rest.responseStatusCode}');
    print('response status text = ${rest.responseStatusText}');
    print('response header: ${rest.responseHeader}');
    print('response body (if any): $responseStr');
    print('---');
    print('LastRequestStartLine: ${rest.lastRequestStartLine}');
    print('LastRequestHeader: ${rest.lastRequestHeader}');
    return;
  }

  final jsonResponse = CkJsonObject();
  jsonResponse.load(responseStr);

  jsonResponse.emitCompact = false;
  print(jsonResponse.emit());

  // {
  //   "used": 3032115,
  //   "allocation": {
  //     ".tag": "individual",
  //     "allocated": 2147483648
  //   }
  // }
  // 
}