Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(AutoIt) Delete All FilesPermanently deletes all files owned by the user without moving it to the trash. This example works by first getting a list of all fileIds, and then iterating over the list to delete each file. See Google Drive Files delete for more information.
Local $bSuccess = 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. $oGAuth = ObjCreate("Chilkat.AuthGoogle") $oGAuth.AccessToken = "GOOGLE-DRIVE-ACCESS-TOKEN" $oRest = ObjCreate("Chilkat.Rest") ; Connect using TLS. Local $bAutoReconnect = True $bSuccess = $oRest.Connect("www.googleapis.com",443,True,$bAutoReconnect) ; Provide the authentication credentials (i.e. the access token) $oRest.SetAuthGoogle($oGAuth) ; Get 10 results per page for testing. (The default page size is 100, with a max of 1000. $oRest.AddQueryParam("pageSize","10") $oJson = ObjCreate("Chilkat.JsonObject") Local $i Local $iNumFiles ; Send the request for the 1st page. Local $sJsonResponse = $oRest.FullRequestNoBody("GET","/drive/v3/files") Local $iPageNumber = 1 Local $sPageToken Local $bContinueLoop = $oRest.LastMethodSuccess And ($oRest.ResponseStatusCode = 200) Local $sFileId $oSaFileIds = ObjCreate("Chilkat.StringArray") While $bContinueLoop = True ConsoleWrite("---- Page " & $iPageNumber & " ----" & @CRLF) $oJson.Load($sJsonResponse) $iNumFiles = $oJson.SizeOfArray("files") $i = 0 While $i < $iNumFiles $oJson.I = $i $sFileId = $oJson.StringOf("files[i].id") ConsoleWrite("name: " & $oJson.StringOf("files[i].name") & @CRLF) ConsoleWrite("id: " & $sFileId & @CRLF) $oSaFileIds.Append($sFileId) $i = $i + 1 Wend ; Get the next page of files. ; If the "nextPageToken" is present in the JSON response, then use it in the "pageToken" parameter ; for the next request. If no "nextPageToken" was present, then this was the last page of files. $sPageToken = $oJson.StringOf("nextPageToken") $bContinueLoop = False Local $bHasMorePages = $oJson.LastMethodSuccess If ($bHasMorePages = True) Then $oRest.ClearAllQueryParams() $oRest.AddQueryParam("pageSize","10") $oRest.AddQueryParam("pageToken",$sPageToken) $sJsonResponse = $oRest.FullRequestNoBody("GET","/drive/v3/files") $bContinueLoop = $oRest.LastMethodSuccess And ($oRest.ResponseStatusCode = 200) $iPageNumber = $iPageNumber + 1 EndIf Wend ; Before actually deleting, check for errors... If ($oRest.LastMethodSuccess <> True) Then ConsoleWrite($oRest.LastErrorText & @CRLF) Exit EndIf ; A successful response will have a status code equal to 200. If ($oRest.ResponseStatusCode <> 200) Then ConsoleWrite("response status code = " & $oRest.ResponseStatusCode & @CRLF) ConsoleWrite("response status text = " & $oRest.ResponseStatusText & @CRLF) ConsoleWrite("response header: " & $oRest.ResponseHeader & @CRLF) ConsoleWrite("response JSON: " & $sJsonResponse & @CRLF) Exit EndIf ; OK, we have the full list of files. Delete each.. $oSbPath = ObjCreate("Chilkat.StringBuilder") $iNumFiles = $oSaFileIds.Count $i = 0 While $i < $iNumFiles $sFileId = $oSaFileIds.GetString($i) $oRest.ClearAllQueryParams() $oSbPath.Clear $oSbPath.Append("/drive/v3/files/") $oSbPath.Append($sFileId) $sJsonResponse = $oRest.FullRequestNoBody("DELETE",$oSbPath.GetAsString()) If ($oRest.LastMethodSuccess <> True) Then ConsoleWrite($oRest.LastErrorText & @CRLF) Exit EndIf ; 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 ($oRest.ResponseStatusCode <> 204) Then ConsoleWrite("response status code = " & $oRest.ResponseStatusCode & @CRLF) ConsoleWrite("response status text = " & $oRest.ResponseStatusText & @CRLF) ConsoleWrite("response header: " & $oRest.ResponseHeader & @CRLF) ConsoleWrite("response JSON: " & $sJsonResponse & @CRLF) Exit EndIf $i = $i + 1 ConsoleWrite($i & ": Deleted " & $sFileId & @CRLF) Wend ConsoleWrite("All Files Deleted." & @CRLF) |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.