Sample code for 30+ languages & platforms
Tcl

List all Labels in the User's Mailbox

See more GMail REST API Examples

List all Labels in the GMail User's Mailbox

Chilkat Tcl Downloads

Tcl

load ./chilkat.dll

set success 0

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

set http [new_CkHttp]

CkHttp_put_AuthToken $http "GMAIL-ACCESS-TOKEN"

set userId "me"
CkHttp_SetUrlVar $http "userId" $userId

set url "https://www.googleapis.com/gmail/v1/users/{$userId}/labels"

CkHttp_put_SessionLogFilename $http "c:/temp/qa_output/sessionLog.txt"

# Get the list of GMail labels as JSON.
set sb [new_CkStringBuilder]

set success [CkHttp_QuickGetSb $http $url $sb]
if {$success != 1} then {
    puts [CkHttp_lastErrorText $http]
    delete_CkHttp $http
    delete_CkStringBuilder $sb
    exit
}

set json [new_CkJsonObject]

CkJsonObject_LoadSb $json $sb
CkJsonObject_put_EmitCompact $json 0
puts [CkJsonObject_emit $json]

if {[CkHttp_get_LastStatus $http] != 200} then {
    puts "Failed."
    delete_CkHttp $http
    delete_CkStringBuilder $sb
    delete_CkJsonObject $json
    exit
}


delete_CkHttp $http
delete_CkStringBuilder $sb
delete_CkJsonObject $json