Sample code for 30+ languages & platforms
Lianja

List all Labels in the User's Mailbox

See more GMail REST API Examples

List all Labels in the GMail User's Mailbox

Chilkat Lianja Downloads

Lianja
llSuccess = .F.

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

loHttp = createobject("CkHttp")
loHttp.AuthToken = "GMAIL-ACCESS-TOKEN"

lcUserId = "me"
loHttp.SetUrlVar("userId",lcUserId)

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

loHttp.SessionLogFilename = "c:/temp/qa_output/sessionLog.txt"

// Get the list of GMail labels as JSON.
loSb = createobject("CkStringBuilder")
llSuccess = loHttp.QuickGetSb(lcUrl,loSb)
if (llSuccess <> .T.) then
    ? loHttp.LastErrorText
    release loHttp
    release loSb
    return
endif

loJson = createobject("CkJsonObject")
loJson.LoadSb(loSb)
loJson.EmitCompact = .F.
? loJson.Emit()

if (loHttp.LastStatus <> 200) then
    ? "Failed."
    release loHttp
    release loSb
    release loJson
    return
endif



release loHttp
release loSb
release loJson