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

Unicode C++
#include <CkHttpCurlW.h>
#include <CkStringBuilderW.h>

void ChilkatSample(void)
    {
    bool success = false;

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

    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.
    CkHttpCurlW curl;
    curl.SetVar(L"access_token",L"BOX_ACCESS_TOKEN");

    curl.ClearTargetOutput(L"*");
    CkStringBuilderW authorizedCommand1;
    authorizedCommand1.SetString(L"curl -X GET \"https://api.box.com/2.0/users/me?fields=id,name,login\" -H \"Authorization: Bearer {{access_token}}\"");
    int headerReplacement1 = authorizedCommand1.Replace(L"{{access_token}}",curl.getVar(L"access_token"));
    success = curl.DoYourThing(authorizedCommand1.getAsString());
    if ((success != true) || (curl.get_StatusCode() != 200)) {
        wprintf(L"Box request failed. HTTP status: %d\n",curl.get_StatusCode());
        wprintf(L"Failure reason: %d\n",curl.get_FailReason());
        wprintf(L"%s\n",curl.responseBodyStr());
        return;
    }

    wprintf(L"%s\n",curl.responseBodyStr());
    }