在框api响应中显示未授权

时间:2012-07-23 07:39:38

标签: php curl box-api

我正在使用文档中提到的box api。我从api_key获得票证,然后从api_key和票证获得auth_token。

但是,当我使用此auth_token获取文件夹列表或文件内容等信息时,我会收到未经授权的错误响应。

这是我的代码:

$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);

代码中可能存在什么问题?

谢谢! 非常感谢你提前!!!

1 个答案:

答案 0 :(得分:1)

确保将$ box_api_key设置为您用于获取故障单和身份验证令牌的api_key。此外,虽然这与您的问题无关,但请使用主机名api.box.com获取所有API V2请求(aka,https://api.box.com/2.0/folders/0