Swift
Swift
Permanently Delete a Specific GMail Message
See more GMail REST API Examples
Immediately and permanently deletes the specified message. This operation cannot be undone. (This is not the same as moving a message to Trash.)Chilkat Swift Downloads
func chilkatTest() {
var success: Bool = false
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
let http = CkoHttp()!
http.authToken = "GMAIL-ACCESS-TOKEN"
// The id of the GMail message to delete.
var id: String? = "1669cc9a926bb8c1"
var userId: String? = "me"
http.setUrlVar(name: "userId", value: "me")
http.setUrlVar(name: "id", value: id)
// Delete the email.
var url: String? = "https://www.googleapis.com/gmail/v1/users/{$userId}/messages/{$id}"
var responseStr: String? = http.quickDeleteStr(url: url)
if http.lastMethodSuccess != true {
print("\(http.lastErrorText!)")
return
}
print("status = \(http.lastStatus.intValue)")
// A 204 response indicate success.
// It is common for HTTP DELETE operations to respond with a 204 status code with an empty body for success.
// You'll find many REST APIs follow this custom..
if http.lastStatus.intValue != 204 {
print("\(responseStr!)")
print("Failed.")
return
}
print("Message deleted!")
}