DataFlex Requires Chilkat v11.5.0+
DataFlex
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 DataFlex Downloads
Use ChilkatAx-win32.pkg
Procedure Test
Boolean iSuccess
Handle hoCurl
Handle hoAuthorizedCommand1
Integer iHeaderReplacement1
String sTemp1
Integer iTemp1
Move False To iSuccess
// Requires Chilkat 11.5.0 or later and a previously unlocked Chilkat bundle.
// See Global Unlock Sample.
// Guide: Box API Guide.
Move False To iSuccess
// 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.
Get Create (RefClass(cComChilkatHttpCurl)) To hoCurl
If (Not(IsComObjectCreated(hoCurl))) Begin
Send CreateComObject of hoCurl
End
Send ComSetVar To hoCurl "access_token" "BOX_ACCESS_TOKEN"
Send ComClearTargetOutput To hoCurl "*"
Get Create (RefClass(cComChilkatStringBuilder)) To hoAuthorizedCommand1
If (Not(IsComObjectCreated(hoAuthorizedCommand1))) Begin
Send CreateComObject of hoAuthorizedCommand1
End
Get ComSetString Of hoAuthorizedCommand1 'curl -X GET "https://api.box.com/2.0/users/me?fields=id,name,login" -H "Authorization: Bearer {{access_token}}"' To iSuccess
Get ComGetVar Of hoCurl "access_token" To sTemp1
Get ComReplace Of hoAuthorizedCommand1 "{{access_token}}" sTemp1 To iHeaderReplacement1
Get ComGetAsString Of hoAuthorizedCommand1 To sTemp1
Get ComDoYourThing Of hoCurl sTemp1 To iSuccess
Get ComStatusCode Of hoCurl To iTemp1
If ((iSuccess <> True) Or (iTemp1 <> 200)) Begin
Get ComStatusCode Of hoCurl To iTemp1
Showln "Box request failed. HTTP status: " iTemp1
Get ComFailReason Of hoCurl To iTemp1
Showln "Failure reason: " iTemp1
Get ComResponseBodyStr Of hoCurl To sTemp1
Showln sTemp1
Procedure_Return
End
Get ComResponseBodyStr Of hoCurl To sTemp1
Showln sTemp1
End_Procedure