asp.net API V2 PHP curl 401未授权响应


Box.net API V2 PHP curl 401 unauthorized response

我目前正在整合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(只是为了看看我是否有任何乐趣),并且对于基本操作来说工作得很好。

任何帮助/指示将不胜感激。

感谢

弗兰基

Frankie, BoxAuth授权机制提供V2 API向后兼容V1令牌。

Authorization: BoxAuth api_key=API_KEY&auth_token=V1_TOKEN

Authorization: Bearer V2_TOKEN

尝试在您的V2 API请求中使用带有BoxAuth标头的v1发布令牌,它应该可以工作。