Pascal (Lazarus/Delphi)
Pascal (Lazarus/Delphi)
Dropbox: Get Space Usage
See more Dropbox Examples
Demonstrates how to get the Dropbox space usage information for the current user's account.Chilkat Pascal (Lazarus/Delphi) Downloads
program ChilkatDemo;
// Demonstrates using the Chilkat Pascal wrapper via the C bridge DLL.
// Builds as a console application under Lazarus (FPC) or Delphi.
{$IFDEF FPC}
{$MODE DELPHI}
{$ENDIF}
{$APPTYPE CONSOLE}
uses
{$IFDEF UNIX}
cthreads,
{$ENDIF}
SysUtils,
CkDllLoader,
Chilkat.Rest,
Chilkat.JsonObject;
// ---------------------------------------------------------------------------
procedure RunDemo;
var
success: Boolean;
rest: TRest;
bTls: Boolean;
port: Integer;
bAutoReconnect: Boolean;
responseStr: string;
jsonResponse: TJsonObject;
begin
success := False;
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
rest := TRest.Create;
// Connect to the www.dropbox.com endpoint.
bTls := True;
port := 443;
bAutoReconnect := True;
success := rest.Connect('api.dropboxapi.com',port,bTls,bAutoReconnect);
if (success <> True) then
begin
WriteLn(rest.LastErrorText);
Exit;
end;
rest.AddHeader('Authorization','Bearer DROPBOX-ACCESS-TOKEN');
responseStr := rest.FullRequestNoBody('POST','/2/users/get_space_usage');
if (rest.LastMethodSuccess <> True) then
begin
WriteLn(rest.LastErrorText);
Exit;
end;
// Success is indicated by a 200 response status code.
if (rest.ResponseStatusCode <> 200) then
begin
// Examine the request/response to see what happened.
WriteLn('response status code = ' + rest.ResponseStatusCode);
WriteLn('response status text = ' + rest.ResponseStatusText);
WriteLn('response header: ' + rest.ResponseHeader);
WriteLn('response body (if any): ' + responseStr);
WriteLn('---');
WriteLn('LastRequestStartLine: ' + rest.LastRequestStartLine);
WriteLn('LastRequestHeader: ' + rest.LastRequestHeader);
Exit;
end;
jsonResponse := TJsonObject.Create;
jsonResponse.Load(responseStr);
jsonResponse.EmitCompact := False;
WriteLn(jsonResponse.Emit());
// {
// "used": 3032115,
// "allocation": {
// ".tag": "individual",
// "allocated": 2147483648
// }
// }
//
rest.Free;
jsonResponse.Free;
end;
// ---------------------------------------------------------------------------
begin
try
RunDemo;
except
on E: Exception do
WriteLn('Unhandled exception: ', E.ClassName, ': ', E.Message);
end;
WriteLn;
{$IFDEF MSWINDOWS}
WriteLn('Press Enter to exit...');
ReadLn;
{$ENDIF}
end.