Sample code for 30+ languages & platforms
Lua Requires Chilkat v11.5.0+

Box: Identify the User Behind an Access Token

See more Box Examples

Identify the account whose permissions and root folder the token uses. Start here when an app cannot see files visible in a personal Box account.

See the Box API guide for setup and the complete workflow.

Chilkat Lua Downloads

Lua
local chilkat = require("chilkat")

-- Requires Chilkat 11.5.0 or later and a previously unlocked Chilkat bundle.
-- See Global Unlock Sample.
-- Guide: Box API Guide.

local success = false

-- Supply an unexpired token obtained with one of the Box authentication examples.
-- A token represents a particular user or service account. IDs must be accessible to it.
local curl = chilkat.HttpCurl.new()
curl:set_var("access_token", "BOX_ACCESS_TOKEN")

curl:clear_target_output("*")
local authorizedCommand1 = chilkat.StringBuilder.new()
authorizedCommand1:set_string("curl -X GET \"https://api.box.com/2.0/users/me?fields=id,name,login\" -H \"Authorization: Bearer {{access_token}}\"")
local headerReplacement1 = authorizedCommand1:replace("{{access_token}}", curl:get_var("access_token"))
success = curl:do_your_thing(authorizedCommand1:get_as_string())
if (not success) or (curl.status_code ~= 200) then
    print("Box request failed. HTTP status: " .. curl.status_code)
    print("Failure reason: " .. curl.fail_reason)
    print(curl.response_body_str)
    return
end

print(curl.response_body_str)