0

I am using the box api as mentioned in the documentation. I get the ticket from api_key and then auth_token from api_key and ticket.

But when i use this auth_token for getting information like folder list or file contents etc. I get unauthorized error in response.

Here is my code:

$auth_token = $_REQUEST["auth_token"];
//exit($auth_token);
$headers = array(
    "Authorization: BoxAuth api_key=".$box_api_key."&auth_token=".$auth_token
);
$http_message = curl_init("https://www.box.com/api/2.0/folders/0");
curl_setopt($http_message, CURLOPT_RETURNTRANSFER, true);
curl_setopt($http_message, CURLOPT_HTTP_VERSION, "CURL_HTTP_VERSION_1_1");
curl_setopt($http_message, CURLOPT_HTTPHEADER, $headers);
curl_setopt($http_message, CURLINFO_HEADER, true);
curl_setopt($http_message, CURLINFO_HEADER_OUT, true);
curl_setopt($http_message, CURLOPT_SSL_VERIFYPEER, false);
$response = curl_exec($http_message);

print($response);

What may be the problem in the code?

Thanks! Thank you very much in advance!!!

PeeHaa
  • 71,436
  • 58
  • 190
  • 262
deovratj
  • 43
  • 5

1 Answers1

1

Make sure you're setting $box_api_key to the api_key you're using to get the ticket and auth token. Also, while this should have no bearing on your question, please use the hostname api.box.com for all API V2 requests (aka, https://api.box.com/2.0/folders/0)

Rob Radez
  • 126
  • 2