Sample code for 30+ languages & platforms
Objective-C

List all Labels in the User's Mailbox

See more GMail REST API Examples

List all Labels in the GMail User's Mailbox

Chilkat Objective-C Downloads

Objective-C
#import <CkoHttp.h>
#import <NSString.h>
#import <CkoStringBuilder.h>
#import <CkoJsonObject.h>

BOOL success = NO;

// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.

CkoHttp *http = [[CkoHttp alloc] init];
http.AuthToken = @"GMAIL-ACCESS-TOKEN";

NSString *userId = @"me";
[http SetUrlVar: @"userId" value: userId];

NSString *url = @"https://www.googleapis.com/gmail/v1/users/{$userId}/labels";

http.SessionLogFilename = @"c:/temp/qa_output/sessionLog.txt";

// Get the list of GMail labels as JSON.
CkoStringBuilder *sb = [[CkoStringBuilder alloc] init];
success = [http QuickGetSb: url sbContent: sb];
if (success != YES) {
    NSLog(@"%@",http.LastErrorText);
    return;
}

CkoJsonObject *json = [[CkoJsonObject alloc] init];
[json LoadSb: sb];
json.EmitCompact = NO;
NSLog(@"%@",[json Emit]);

if ([http.LastStatus intValue] != 200) {
    NSLog(@"%@",@"Failed.");
    return;
}