0

我对 Box 环境完全陌生。我正在使用当前代码在网站上的 web 目录中显示所有图像,其中最新文件首先列出:

<?php
   $path = 'images/';
   $files = scandir($path);
   $ignore = array( 'cgi-bin', '.', '..');

   # remove ignored files
   $files = array_filter($files, function($file) use ($ignore) {return !in_array($file, $ignore);});

   # get the modification time for each file
   $times = array_map(function($file) use ($path) {return filemtime("$path/$file");}, $files);

   # sort the times array while sorting the files array as well
   array_multisort($times, SORT_DESC, SORT_NUMERIC, $files);

   foreach ($files as $file) {
      echo '<div class="item">';
      echo '<a title="&copy;2013" rel="gallery" class="fancybox" href="images/'.$file.'"><img   src="images/'.$file.'" alt="'.$image.'" /></a>';
      echo '</div>';
   }
?>

我想集成 Box API 以从我的 Box 文件夹而不是 Web 文件夹中获取文件。当前的 API 可以做到这一点吗?我尝试使用以下内容显示 Open Access 文件夹的内容:

<?php
   $params = array();
   $params['shared_link'] = array("access"=> "Open");
   $params = json_encode($params);
   echo $params;
   $key = "[my api key]";
   $token = "[token]";
   $ch = curl_init();

   curl_setopt($ch, CURLOPT_URL, "https://api.box.com/2.0/folders/kvpemb6rgohhr448r935"); //my box folder
   curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
   curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
   curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
   curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
   curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json', "-H Authorization: Bearer $key",'Content-Length: ' . strlen($params), 'X-HTTP-Method-Override: GET'));
   $result = curl_exec($ch);
   curl_close($ch);
   print_r($result);
?>

但只接收页面上的数组值"{"shared_link":{"access":"Open"}}"

我已经用尽了在 Google 和 Stackoverflow 上的搜索能力,并且没有遇到试图完成此任务的线程。感谢您的任何指导/帮助。

4

2 回答 2

0

在这里,也许这会对您有所帮助:

function getPictures($folderid, $access_token){
    //===================== Default cUrl options =================
    $options = array(
        CURLOPT_SSL_VERIFYPEER => false,
        CURLOPT_VERBOSE        => true,
        CURLOPT_HEADER         => false,
        CURLINFO_HEADER_OUT    => false,
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_FOLLOWLOCATION => false,
    );
    $options[CURLOPT_HTTPHEADER] = array ("Authorization: Bearer ".$access_token);

    //======================= Proper url ==========================
    $url = "https://api.box.com/2.0/folders/{$folderid}/items";

    //======================= cUrl call ===========================
    $ch = curl_init($url);
    curl_setopt_array($ch, $options);
    $result = curl_exec($ch);
    curl_close($ch);
    $result = json_decode($result, true);

    // =============== Loop over items to search for photos =================
    $rez = array();
    if (isset($result['total_count']) && $result['total_count'] > 0){
        foreach ($result['entries'] as $elements){
            if (isPic($elements['name'])) $rez[] = $elements['name'];
        }
    }

    return $rez;
}

function isPic($value){
    $value = explode('.', $value);
    if (count($value) < 2) return false;
    $extensions = array ('jpg', 'bmp', 'png', 'gif');
    return in_array($value[1], $extensions);
}

来自 Box.com api 的有用链接:

http://developers.box.com/docs/#folders-retrieve-a-folders-items

或者

http://developers.box.com/docs/#search

于 2013-09-24T13:09:44.043 回答
0

If you want to retrieve the items from an 'Open' folder in Box, I recommend you check out this endpoint. http://developers.box.com/docs/#shared-items

于 2013-09-20T00:24:10.083 回答