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

C
#include <C_CkHttpCurl.h>
#include <C_CkStringBuilder.h>

void ChilkatSample(void)
    {
    BOOL success;
    HCkHttpCurl curl;
    HCkStringBuilder authorizedCommand1;
    int headerReplacement1;

    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.
    curl = CkHttpCurl_Create();
    CkHttpCurl_SetVar(curl,"access_token","BOX_ACCESS_TOKEN");

    CkHttpCurl_ClearTargetOutput(curl,"*");
    authorizedCommand1 = CkStringBuilder_Create();
    CkStringBuilder_SetString(authorizedCommand1,"curl -X GET \"https://api.box.com/2.0/users/me?fields=id,name,login\" -H \"Authorization: Bearer {{access_token}}\"");
    headerReplacement1 = CkStringBuilder_Replace(authorizedCommand1,"{{access_token}}",CkHttpCurl_getVar(curl,"access_token"));
    success = CkHttpCurl_DoYourThing(curl,CkStringBuilder_getAsString(authorizedCommand1));
    if ((success != TRUE) || (CkHttpCurl_getStatusCode(curl) != 200)) {
        printf("Box request failed. HTTP status: %d\n",CkHttpCurl_getStatusCode(curl));
        printf("Failure reason: %d\n",CkHttpCurl_getFailReason(curl));
        printf("%s\n",CkHttpCurl_responseBodyStr(curl));
        CkHttpCurl_Dispose(curl);
        CkStringBuilder_Dispose(authorizedCommand1);
        return;
    }

    printf("%s\n",CkHttpCurl_responseBodyStr(curl));


    CkHttpCurl_Dispose(curl);
    CkStringBuilder_Dispose(authorizedCommand1);

    }