Sample code for 30+ languages & platforms
Swift

Empty Trash

See more Google Drive Examples

Permanently deletes all of the user's trashed files.

Chilkat Swift Downloads

Swift

func chilkatTest() {
    var success: Bool = 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.

    let gAuth = CkoAuthGoogle()!
    gAuth.accessToken = "GOOGLE-DRIVE-ACCESS-TOKEN"

    let rest = CkoRest()!

    // Connect using TLS.
    var bAutoReconnect: Bool = true
    success = rest.connect(hostname: "www.googleapis.com", port: 443, tls: true, autoReconnect: bAutoReconnect)

    // Provide the authentication credentials (i.e. the access token)
    rest.setAuthGoogle(authProvider: gAuth)

    var jsonResponse: String? = rest.fullRequestNoBody(httpVerb: "DELETE", uriPath: "/drive/v3/files/trash")
    if rest.lastMethodSuccess != true {
        print("\(rest.lastErrorText!)")
        return
    }

    // 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.intValue != 204 {
        print("response status code = \(rest.responseStatusCode.intValue)")
        print("response status text = \(rest.responseStatusText!)")
        print("response header: \(rest.responseHeader!)")
        print("response JSON: \(jsonResponse!)")
        return
    }

    print("Trash Emptied!")

}