0

在php中上传box api的文件方法的新版本不起作用

这是我用来发送请求的代码

$uploadfile =$_SESSION['uploadfile'];
            $fileid =$_SESSION['fileid'];
            $myuri='https://upload.box.com/api/2.0/files/'.$fileid.'/content';
            $curl2 = curl_init();

            curl_setopt($curl2, CURLOPT_HTTPHEADER, array('Authorization: Bearer '.$_SESSION['usertoken']));
            curl_setopt_array($curl2, array(
                CURLOPT_RETURNTRANSFER => 1,
                CURLOPT_URL => $myuri,
                CURLOPT_POST => 1,
                CURLOPT_POSTFIELDS => array(
                filename => "@".$uploadfile
                )
            ));
            // Send the request & save response to $resp
            $data = curl_exec($curl2);
            $data = json_decode($data);

我从框中收到以下错误响应:

object(stdClass)#1 (7) { ["type"]=> string(5) "error" ["status"]=> int(400) ["code"]=> string(11) "bad_request" ["context_info"]=> object(stdClass)#2 (1) { ["errors"]=> array(1) { [0]=> object(stdClass)#3 (3) { ["reason"]=> string(17) "missing_parameter" ["name"]=> string(6) "parent" ["message"]=> string(20) "'parent' is required" } } } ["help_url"]=> string(38) "http://developers.box.com/docs/#errors" ["message"]=> string(11) "Bad Request" ["request_id"]=> string(23) "1638286030525d1c87c6a1e" } 

根据他们的文档,我只需要我要上传的文件的文件名和我要覆盖的文件的文件 ID,它没有说明需要父母我在这里缺少什么?这是一个错误还是文档错误?

可以在此处找到文档http://developers.box.com/docs/#files-upload-a-new-version-of-a-file

4

1 回答 1

0

我发现盒子文档很糟糕。如果它在文档中作为参数列出,那么明智的说法是它需要天气它是否按要求列出。这是工作代码

$fileid = $_REQUEST["fileid"];
        $uploadfile =$_SESSION['uploadfile'];
        $myuri="https://api.box.com/2.0/files/".$fileid;
        $curl = curl_init($myuri);
        curl_setopt($curl, CURLOPT_HTTPHEADER, array('Authorization: Bearer '.$_SESSION['usertoken']));
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
        $data = curl_exec($curl);
        curl_close($curl);
        $data = json_decode($data);
        //var_dump($data);
        $etag =$data->etag;
        date_default_timezone_set("UTC");
        $timestamp = date(DATE_ATOM);
        $curl2 = curl_init();
        curl_setopt($curl2, CURLOPT_HTTPHEADER, array('If-Match: '.$etag,'Authorization: Bearer '.$_SESSION['usertoken']));
        curl_setopt_array($curl2, array(
            CURLOPT_RETURNTRANSFER => 1,
            CURLOPT_URL => 'https://upload.box.com/api/2.0/files/'.$fileid.'/content',
            CURLOPT_POST => 1,
            CURLOPT_POSTFIELDS => array(
                filename => "@".$uploadfile,
                content_modified_at =>$timestamp
                )
            ));

        $data2 = curl_exec($curl2);
        $data2 = json_decode($data2);
于 2013-10-18T07:27:07.387 回答