Google Drive: Delete File
Delete files or folders on Google Drive.You can delete multiple files or folders at once.When you delete multiple ones,you should write one file/folder ID on each line.
https://support.questetra.com/addons/googledrive-folderdelete/
2019-01-21 (C) Questetra, Inc. (MIT License)
Configs
  • C1: User who connect to Google Drive *
  • I1: Data Item with File/ Folder IDs to delete *
Script
main();
function main(){
  const fileIds = engine.findDataByNumber(configs.get("FileIdsItem"));
  if (fileIds == null) {
    throw "File IDs aren't set.";
  }
  const linesArray = fileIds.split("\n");
  const numOfLines = linesArray.length;
  if (numOfLines > httpClient.getRequestingLimit()){
  	throw "Number of File IDs is over the limit."
  }
  
  const userId = configs.get("UserID");
  const quser = quserDao.findById(parseInt(userId));
  if (quser == null) {
    throw "User not found:" + userId;
  }
  engine.log("User Name:" + quser.getName() + "\n");
  let token;
  try{
    token = httpClient.getGoogleOAuth2Token(quser, "Drive");
  }catch(e){
    throw "This User has not connected with Google Drive."
  }
  for (let i = 0; i < numOfLines; i++){
    deleteFile(token, linesArray[i])
  }
}
function deleteFile(token, fileId) {
  const url = 'https://www.googleapis.com/drive/v3/files/' + fileId;
  let response = httpClient.begin()
    .bearer(token)
    .queryParam("supportsTeamDrives","true")
    .delete(url);
  const status = response.getStatusCode();
  if (status >= 300) {
    const error = "Failed to delete:" + fileId + "\n" + status + "\n" + response.getResponseAsString();
    throw error;
  }else{
    engine.log("File ID" + fileId + "\n" + "status:" + status + "\n"+"delete successful" + "\n");
  }
}

Download

google-drive-file-delete.xml

Capture

Notes

  1. Users of C1 need to have configured connection with Google Drive at [Account Settings] > [Google Connectivity]

See also