Swift 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



func chilkatTest() {
    let rest = CkoRest()
    var success: Bool

    //   Provide a previously obtained OAuth2 access token.
    let oauth2 = CkoOAuth2()
    oauth2.AccessToken = "OAUTH2_ACCESS_TOKEN"
    rest.SetAuthOAuth2(oauth2)

    success = rest.Connect("www.googleapis.com", port: 443, tls: true, autoReconnect: true)
    if success != true {
        print("\(rest.LastErrorText)")
        return
    }

    rest.AddQueryParam("includeTeamDriveItems", value: "true")
    rest.AddQueryParam("supportsTeamDrives", value: "true")

    let sbResponse = CkoStringBuilder()
    success = rest.FullRequestNoBodySb("DELETE", uriPath: "/drive/v3/files/1BXNQ4sMDD1WibOtcYqgQlwJa0MAa6rTQ/permissions/anyoneWithLink", sb: sbResponse)
    if success != true {
        print("\(rest.LastErrorText)")
        return
    }

    if rest.ResponseStatusCode.integerValue != 204 {
        print("Received error response code: \(rest.ResponseStatusCode.integerValue)")
        print("Response body:")
        print("\(sbResponse.GetAsString())")
        return
    }

    print("Example Completed.")

}