我对Box环境完全陌生。我正在使用当前代码在网站上的网络目录中显示所有图像,其中首先列出最新文件:
<?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="©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上耗尽了我的搜索功能,并且没有遇到尝试完成此任务的线程。感谢您提供任何指导/帮助。
答案 0 :(得分:0)
如果您想从Box中的“打开”文件夹中检索项目,我建议您查看此端点。 http://developers.box.com/docs/#shared-items
答案 1 :(得分: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
或