Sample code for 30+ languages & platforms
Go

List all Labels in the User's Mailbox

See more GMail REST API Examples

List all Labels in the GMail User's Mailbox

Chilkat Go Downloads

Go
    success := false

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

    http := chilkat.NewHttp()
    http.SetAuthToken("GMAIL-ACCESS-TOKEN")

    userId := "me"
    http.SetUrlVar("userId",userId)

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

    http.SetSessionLogFilename("c:/temp/qa_output/sessionLog.txt")

    // Get the list of GMail labels as JSON.
    sb := chilkat.NewStringBuilder()
    success = http.QuickGetSb(url,sb)
    if success != true {
        fmt.Println(http.LastErrorText())
        http.DisposeHttp()
        sb.DisposeStringBuilder()
        return
    }

    json := chilkat.NewJsonObject()
    json.LoadSb(sb)
    json.SetEmitCompact(false)
    fmt.Println(*json.Emit())

    if http.LastStatus() != 200 {
        fmt.Println("Failed.")
        http.DisposeHttp()
        sb.DisposeStringBuilder()
        json.DisposeJsonObject()
        return
    }


    http.DisposeHttp()
    sb.DisposeStringBuilder()
    json.DisposeJsonObject()