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

Android™
// Important: Don't forget to include the call to System.loadLibrary
// as shown at the bottom of this code sample.
package com.test;

import android.app.Activity;
import com.chilkatsoft.*;

import android.widget.TextView;
import android.os.Bundle;

public class SimpleActivity extends Activity {

  private static final String TAG = "Chilkat";

  // Called when the activity is first created.
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    boolean 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.
    CkHttpCurl curl = new CkHttpCurl();
    curl.SetVar("access_token","BOX_ACCESS_TOKEN");

    curl.ClearTargetOutput("*");
    CkStringBuilder authorizedCommand1 = new CkStringBuilder();
    authorizedCommand1.SetString("curl -X GET \"https://api.box.com/2.0/users/me?fields=id,name,login\" -H \"Authorization: Bearer {{access_token}}\"");
    int headerReplacement1 = authorizedCommand1.Replace("{{access_token}}",curl.getVar("access_token"));
    success = curl.DoYourThing(authorizedCommand1.getAsString());
    if ((success != true) or (curl.get_StatusCode() != 200)) {
        Log.i(TAG, "Box request failed. HTTP status: " + String.valueOf(curl.get_StatusCode()));
        Log.i(TAG, "Failure reason: " + String.valueOf(curl.get_FailReason()));
        Log.i(TAG, curl.responseBodyStr());
        return;
        }

    Log.i(TAG, curl.responseBodyStr());

  }

  static {
      System.loadLibrary("chilkat");

      // Note: If the incorrect library name is passed to System.loadLibrary,
      // then you will see the following error message at application startup:
      //"The application <your-application-name> has stopped unexpectedly. Please try again."
  }
}