Sample code for 30+ languages & platforms
Xbase++ 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 Xbase++ Downloads

Xbase++
LOCAL nSuccess
LOCAL oCurl
LOCAL oAuthorizedCommand1
LOCAL nHeaderReplacement1

nSuccess := 0

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

nSuccess := 0

//  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.
oCurl := CreateObject("Chilkat.HttpCurl")
oCurl:SetVar("access_token", "BOX_ACCESS_TOKEN")

oCurl:ClearTargetOutput("*")
oAuthorizedCommand1 := CreateObject("Chilkat.StringBuilder")
oAuthorizedCommand1:SetString('curl -X GET "https://api.box.com/2.0/users/me?fields=id,name,login" -H "Authorization: Bearer {{access_token}}"')
nHeaderReplacement1 := oAuthorizedCommand1:Replace("{{access_token}}", oCurl:GetVar("access_token"))
nSuccess := oCurl:DoYourThing(oAuthorizedCommand1:GetAsString())
IF ((nSuccess != 1) .OR. (oCurl:StatusCode != 200))
    ? "Box request failed. HTTP status: " + Str(oCurl:StatusCode)
    ? "Failure reason: " + Str(oCurl:FailReason)
    ? oCurl:ResponseBodyStr
    oCurl:destroy()
    oAuthorizedCommand1:destroy()
    RETURN
ENDIF

? oCurl:ResponseBodyStr

oCurl:destroy()
oAuthorizedCommand1:destroy()