0

我正在尝试在 Box 上创建一个简单的文件夹,但我遇到了困难。我不断收到此错误:

{"type":"error","status":404,"code":"not_found","help_url":"http://developers.box.com/docs/#errors","message":"不是找到","re​​quest_id":"71794126250a0c2f00fe35"}

这是我的代码:

$parent = array();
$parent['id'] = '0';
$params = array();
$params['name'] = 'Testfolder';
$params['parent'] = $parent;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.box.com/2.0/folders");
curl_setopt($ch, CURLOPT_HEADER, false); 
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Authorization: BoxAuth api_key={myAPIkey}&auth_token={myToken}"));
$result = curl_exec($ch);
curl_close($ch);
print_r($result);

我错过了什么。请帮忙。提前致谢。

4

1 回答 1

0

根据BOX 文档

默认情况下,请求正文数据应为 JSON,响应正文数据以 JSON 格式发回。

$parent = array();
$parent['id'] = '0';
$params = array();
$params['name'] = 'Testfolder';
$params['parent'] = $parent;

$params = json_encode($params);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.box.com/2.0/folders");
curl_setopt($ch, CURLOPT_HEADER, false); 
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("'Content-Type: application/json',                                                                                
    'Content-Length: ' . strlen($params), Authorization: BoxAuth api_key={myAPIkey}&auth_token={myToken}"));
$result = curl_exec($ch);
curl_close($ch);
print_r($result);
于 2012-11-12T10:30:22.297 回答