Sample code for 30+ languages & platforms
Xbase++

List all Labels in the User's Mailbox

See more GMail REST API Examples

List all Labels in the GMail User's Mailbox

Chilkat Xbase++ Downloads

Xbase++
LOCAL nSuccess
LOCAL oHttp
LOCAL cUserId
LOCAL cUrl
LOCAL oSb
LOCAL oJson

nSuccess := 0

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

oHttp := CreateObject("Chilkat.Http")
oHttp:AuthToken := "GMAIL-ACCESS-TOKEN"

cUserId := "me"
oHttp:SetUrlVar("userId", cUserId)

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

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

//  Get the list of GMail labels as JSON.
oSb := CreateObject("Chilkat.StringBuilder")
nSuccess := oHttp:QuickGetSb(cUrl, oSb)
IF (nSuccess != 1)
    ? oHttp:LastErrorText
    oHttp:destroy()
    oSb:destroy()
    RETURN
ENDIF

oJson := CreateObject("Chilkat.JsonObject")
oJson:LoadSb(oSb)
oJson:EmitCompact := 0
? oJson:Emit()

IF (oHttp:LastStatus != 200)
    ? "Failed."
    oHttp:destroy()
    oSb:destroy()
    oJson:destroy()
    RETURN
ENDIF

oHttp:destroy()
oSb:destroy()
oJson:destroy()