我目前正在将 Box.net 集成到一个网站中,并且在身份验证后尝试访问操作时遇到了问题。
我正在验证并检索我的令牌,但是无论令牌处于活动状态,我收到的每个响应都是未经授权的 401。
我的测试代码:
$header = array('Authorization: BoxAuth api_key='.$apikey.'&auth_token='.$auth);
$curl = curl_init();
curl_setopt( $curl, CURLOPT_URL, 'https://api.box.com/2.0/folders/0');
curl_setopt( $curl, CURLOPT_HTTPHEADER, $header);
curl_setopt( $curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt( $curl, CURLOPT_HTTP_VERSION, "CURL_HTTP_VERSION_1_1");
curl_setopt( $curl, CURLOPT_VERBOSE, true );
//curl_setopt( $curl, CURLINFO_HEADER, true);
curl_setopt( $curl, CURLINFO_HEADER_OUT, true);
curl_setopt( $curl, CURLOPT_SSL_VERIFYPEER, false);
//curl_setopt( $curl, CURLOPT_SSL_VERIFYHOST, 2);
$res = curl_exec( $curl );
if ($res === false)
{
print_r('Curl error: ' . curl_error($curl));
}
var_dump( curl_getinfo($curl) );
curl_close($curl);
var_dump($res);
请求转储:
array(22) {
["url"]=>
string(33) "https://api.box.com/2.0/folders/0"
["content_type"]=>
string(16) "application/json"
["http_code"]=>
int(401)
["header_size"]=>
int(203)
["request_size"]=>
int(172)
["filetime"]=>
int(-1)
["ssl_verify_result"]=>
int(0)
["redirect_count"]=>
int(0)
["total_time"]=>
float(0.783732)
["namelookup_time"]=>
float(0.005711)
["connect_time"]=>
float(0.15543)
["pretransfer_time"]=>
float(0.479779)
["size_upload"]=>
float(0)
["size_download"]=>
float(171)
["speed_download"]=>
float(218)
["speed_upload"]=>
float(0)
["download_content_length"]=>
float(171)
["upload_content_length"]=>
float(0)
["starttransfer_time"]=>
float(0.783576)
["redirect_time"]=>
float(0)
["certinfo"]=>
array(0) {
}
["request_header"]=>
string(172) "GET /2.0/folders/0 HTTP/1.1
Host: api.box.com
Accept: */*
Authorization: BoxAuth api_key=xxxxxxxxxxxxxx&auth_token=xxxxxxxxxxxxxxx
"
}
回复:
string(171) "{"type":"error","status":401,"code":"unauthorized","help_url":"http:\/\/developers.box.com\/docs\/#errors","message":"Unauthorized","request_id":"xxxxxxxxxxxxxx"}"
作为参考,我已经通过 Sean Rose 编写的 Box_Rest_Client 尝试了 v1 api(只是看看我是否有任何乐趣),并且对于基本操作来说效果很好。
任何帮助/指针将不胜感激。
谢谢
弗兰基