Sample code for 30+ languages & platforms
Lua

Dropbox: Get Space Usage

See more Dropbox Examples

Demonstrates how to get the Dropbox space usage information for the current user's account.

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 rest = chilkat.Rest.new()

-- Connect to the www.dropbox.com endpoint.
local bTls = true
local port = 443
local bAutoReconnect = true
local success = rest:connect("api.dropboxapi.com", port, bTls, bAutoReconnect)
if not success then
    print(rest.last_error_text)
    return
end

rest:add_header("Authorization", "Bearer DROPBOX-ACCESS-TOKEN")

local responseStr = rest:full_request_no_body("POST", "/2/users/get_space_usage")
if not rest.last_method_success then
    print(rest.last_error_text)
    return
end

-- Success is indicated by a 200 response status code.
if rest.response_status_code ~= 200 then
    -- Examine the request/response to see what happened.
    print("response status code = " .. rest.response_status_code)
    print("response status text = " .. rest.response_status_text)
    print("response header: " .. rest.response_header)
    print("response body (if any): " .. responseStr)
    print("---")
    print("LastRequestStartLine: " .. rest.last_request_start_line)
    print("LastRequestHeader: " .. rest.last_request_header)
    return
end

local jsonResponse = chilkat.JsonObject.new()
jsonResponse:load(responseStr)

jsonResponse.emit_compact = false
print(jsonResponse:emit())

-- {
--   "used": 3032115,
--   "allocation": {
--     ".tag": "individual",
--     "allocated": 2147483648
--   }
-- }
--