Objective-C Requires Chilkat v11.0.0+
Objective-C
Permanently delete one Gmail message
See more GMail REST API Examples
Permanent deletion. Supply the ID of a message you intend to erase. This removes it immediately and cannot be undone. Use Move one Gmail message to Trash for recoverable removal. Google requires the full mail scope for permanent deletion.
Authorize the application with https://mail.google.com/. The example reads the access token from gmail-token.json in a private working directory. Authorize a desktop application.
Chilkat Objective-C Downloads
#import <CkoJsonObject.h>
#import <CkoHttp.h>
#import <CkoHttpResponse.h>
#import <CkoStringBuilder.h>
BOOL success = NO;
// Assumes Chilkat is unlocked. See Global Unlock Sample.
CkoJsonObject *token = [[CkoJsonObject alloc] init];
success = [token LoadFile: @"gmail-token.json"];
if (success != YES) {
NSLog(@"%@",@"Could not read gmail-token.json from the private working directory.");
return;
}
if (([[token JsonTypeOf: @"access_token"] intValue] != 1) || ([token StringOfEquals: @"access_token" value: @"" caseSensitive: YES] == YES)) {
NSLog(@"%@",@"An OAuth access token is required.");
return;
}
CkoHttp *http = [[CkoHttp alloc] init];
http.RequireSslCertVerify = YES;
http.AuthToken = [token StringOf: @"access_token"];
CkoHttpResponse *resp = [[CkoHttpResponse alloc] init];
CkoJsonObject *reply = [[CkoJsonObject alloc] init];
CkoStringBuilder *url = [[CkoStringBuilder alloc] init];
[url Append: @"https://gmail.googleapis.com/gmail/v1/users/me/messages/"];
[url Append: @"GMAIL_MESSAGE_ID"];
success = [http HttpNoBody: @"DELETE" url: [url GetAsString] response: resp];
if ([resp.StatusCode intValue] == 0) {
NSLog(@"%@",@"Gmail did not return an HTTP response.");
return;
}
if ((success != YES) || ([resp.StatusCode intValue] < 200) || ([resp.StatusCode intValue] >= 300)) {
NSLog(@"%@%d",@"Gmail HTTP ",[resp.StatusCode intValue]);
success = [reply Load: resp.BodyStr];
if (success == YES) {
NSLog(@"%@",[reply StringOf: @"error.message"]);
}
return;
}
// Successful deletion has no message body to parse.
NSLog(@"%@",@"Message permanently deleted.");