我正在使用smugphp并完成了此代码块之上的所有登录内容。我想获取我在smugmug网站上创建的文件夹结构。不幸的是,这只给了我那个类别和文件夹树的叶子名称。似乎没有办法获得中间文件夹。
非常感谢任何帮助。
$categories=$f->categories_get();
$subcategories=$f->subcategories_getAll();
echo "CATEGORIES<br>";
for ($i=0;$i<count($categories);$i++){
print_r($categories[$i]);
echo "<br><br>";
}
echo "subcategories<br>";
for ($i=0;$i<count($subcategories);$i++){
print_r($subcategories[$i]);
echo "<br><br>";
}
答案 0 :(得分:0)
我不知道这是最好还是最干净的解决方案,但是通过下面的代码,我可以欺骗smugmug给我想要的东西。我强制它进行深度优先搜索,然后忽略重复。我希望这有助于其他人,但如果有更好的解决方案,请告诉我。
<?php
require_once("phpSmug/phpSmug.php");
class Smugmug{
private $f;
private $folders;
public function __construct(){
$this->f=new phpSmug("APIKey=MfDv7qWG8VZt2tSK2DV7rZx10YXnu7UF","APIVer=1.2.2");
$this->f->login("APIKey=MfDv7qWG8VZt2tSK2DV7rZx10YXnu7UF","EmailAddress=EMAIL@gmail.com","Password=PASSWORD");
$this->folders=[];
}
public function get_folders(){
$this->folders=$this->_get_folders();
}
private function new_id($id,$folders){
if (!isset($folders)){
return False;
}
for ($i=0;$i<count($folders);$i++){
if ($id==$folders[$i]['id']){
return False;
}
if ($this->new_id($id,$folders[$i]['subfolders'])==False){
return False;
}
}
return True;
}
private function _get_folders($id=-1){
$folders=[];
if ($id==-1){
$categories = $this->f->categories_get();
} else {
$categories = $this->f->subcategories_get("CategoryID=$id");
}
$k=0;
for ($i=0;$i<count($categories);$i++){
$folder['id']=$categories[$i]['id'];
if ($this->new_id($folder['id'],$folders)){
$folder['name']=$categories[$i]['Name'];
$folders[$i]=$folder;
$subfolders=$this->_get_folders($folder['id']);
$folders[$i]['subfolders']=$subfolders;
}
}
return $folders;
}
public function print_folders(){
$this->_print_folders($this->folders);
}
private function _print_folders($folders,$prefix=""){
for ($i=0;$i<count($folders);$i++){
echo $prefix.$folders[$i]['name']."<br>";
$this->_print_folders($folders[$i]['subfolders'],$prefix."-");
}
}
}
?>