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

Tcl

load ./chilkat.dll

set success 0

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

set success 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.
set curl [new_CkHttpCurl]

CkHttpCurl_SetVar $curl "access_token" "BOX_ACCESS_TOKEN"

CkHttpCurl_ClearTargetOutput $curl "*"
set authorizedCommand1 [new_CkStringBuilder]

CkStringBuilder_SetString $authorizedCommand1 "curl -X GET \"https://api.box.com/2.0/users/me?fields=id,name,login\" -H \"Authorization: Bearer {{access_token}}\""
set headerReplacement1 [CkStringBuilder_Replace $authorizedCommand1 "{{access_token}}" [CkHttpCurl_getVar $curl "access_token"]]
set success [CkHttpCurl_DoYourThing $curl [CkStringBuilder_getAsString $authorizedCommand1]]
if {expr [$success != 1]  ||  [[CkHttpCurl_get_StatusCode $curl] != 200]} then {
    puts "Box request failed. HTTP status: [CkHttpCurl_get_StatusCode $curl]"
    puts "Failure reason: [CkHttpCurl_get_FailReason $curl]"
    puts [CkHttpCurl_responseBodyStr $curl]
    delete_CkHttpCurl $curl
    delete_CkStringBuilder $authorizedCommand1
    exit
}

puts [CkHttpCurl_responseBodyStr $curl]

delete_CkHttpCurl $curl
delete_CkStringBuilder $authorizedCommand1