Sample code for 30+ languages & platforms
Lua

List all Labels in the User's Mailbox

See more GMail REST API Examples

List all Labels in the GMail User's Mailbox

Chilkat Lua Downloads

Lua
local chilkat = require("chilkat")

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

local http = chilkat.Http.new()
http.auth_token = "GMAIL-ACCESS-TOKEN"

local userId = "me"
http:set_url_var("userId", userId)

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

http.session_log_filename = "c:/temp/qa_output/sessionLog.txt"

-- Get the list of GMail labels as JSON.
local sb = chilkat.StringBuilder.new()
local success = http:quick_get_sb(url, sb)
if not success then
    print(http.last_error_text)
    return
end

local json = chilkat.JsonObject.new()
json:load_sb(sb)
json.emit_compact = false
print(json:emit())

if http.last_status ~= 200 then
    print("Failed.")
    return
end