Sample code for 30+ languages & platforms
Pascal (Lazarus/Delphi)

Empty Trash

See more Google Drive Examples

Permanently deletes all of the user's trashed files.

Chilkat Pascal (Lazarus/Delphi) Downloads

Pascal (Lazarus/Delphi)
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.AuthGoogle;

// ---------------------------------------------------------------------------

procedure RunDemo;
var
  success: Boolean;
  gAuth: TAuthGoogle;
  rest: TRest;
  bAutoReconnect: Boolean;
  jsonResponse: string;

begin
  success := False;

  success := True;

  //  It requires the Chilkat API to have been previously unlocked.
  //  See Global Unlock Sample for sample code.

  //  This example uses a previously obtained access token having permission for the 
  //  Google Drive scope.

  gAuth := TAuthGoogle.Create;
  gAuth.AccessToken := 'GOOGLE-DRIVE-ACCESS-TOKEN';

  rest := TRest.Create;

  //  Connect using TLS.
  bAutoReconnect := True;
  success := rest.Connect('www.googleapis.com',443,True,bAutoReconnect);

  //  Provide the authentication credentials (i.e. the access token)
  rest.SetAuthGoogle(gAuth);

  jsonResponse := rest.FullRequestNoBody('DELETE','/drive/v3/files/trash');
  if (rest.LastMethodSuccess <> True) then
    begin
      WriteLn(rest.LastErrorText);
      Exit;
    end;

  //  A successful response will have a status code equal to 204 and the response body is empty.
  //  (If not successful, then there should be a JSON response body with information..)
  if (rest.ResponseStatusCode <> 204) then
    begin
      WriteLn('response status code = ' + rest.ResponseStatusCode);
      WriteLn('response status text = ' + rest.ResponseStatusText);
      WriteLn('response header: ' + rest.ResponseHeader);
      WriteLn('response JSON: ' + jsonResponse);
      Exit;
    end;

  WriteLn('Trash Emptied!');


  gAuth.Free;
  rest.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.