Delphi DLL Google Drive: Delete a Particular File Permission

Back to Index

Deletes the permission having an id = "anyoneWithLink". (In this example the file id = 1BXNQ4sMDD1WibOtcYqgQlwJa0MAa6rTQ)

Documentation: https://developers.google.com/drive/v3/reference/permissions/delete


var
rest: HCkRest;
success: Boolean;
oauth2: HCkOAuth2;
sbResponse: HCkStringBuilder;

begin
rest := CkRest_Create();

//   Provide a previously obtained OAuth2 access token.
oauth2 := CkOAuth2_Create();
CkOAuth2_putAccessToken(oauth2,'OAUTH2_ACCESS_TOKEN');
CkRest_SetAuthOAuth2(rest,oauth2);

success := CkRest_Connect(rest,'www.googleapis.com',443,True,True);
if (success <> True) then
  begin
    Memo1.Lines.Add(CkRest__lastErrorText(rest));
    Exit;
  end;

CkRest_AddQueryParam(rest,'includeTeamDriveItems','true');
CkRest_AddQueryParam(rest,'supportsTeamDrives','true');

sbResponse := CkStringBuilder_Create();
success := CkRest_FullRequestNoBodySb(rest,'DELETE','/drive/v3/files/1BXNQ4sMDD1WibOtcYqgQlwJa0MAa6rTQ/permissions/anyoneWithLink',sbResponse);
if (success <> True) then
  begin
    Memo1.Lines.Add(CkRest__lastErrorText(rest));
    Exit;
  end;

if (CkRest_getResponseStatusCode(rest) <> 204) then
  begin
    Memo1.Lines.Add('Received error response code: ' + IntToStr(CkRest_getResponseStatusCode(rest)));
    Memo1.Lines.Add('Response body:');
    Memo1.Lines.Add(CkStringBuilder__getAsString(sbResponse));
    Exit;
  end;

Memo1.Lines.Add('Example Completed.');

CkRest_Dispose(rest);
CkOAuth2_Dispose(oauth2);
CkStringBuilder_Dispose(sbResponse);