我使用PHP获取文件夹列表,然后使用Google文档中的文档(两个API请求)。
获取文件夹列表,我可以获取他们的文件夹ID,这很好。
但是,在获取文档列表时,它会返回类别,而这些只包含文件夹的名称。
我的问题存在,因为我有两个同名的文件夹,我的代码是合并这些文件,因为它们具有相同的名称。
我用来获取文件夹中文档列表的函数:
/**
* Gets a list of 'internal' IDs of docs within a certain folder
* @global Mixed $fileslist
* @param String $folder
* @return Array
*/
function getDocumentsInFolder($folder) {
global $fileslist;
$docs = array();
foreach ($fileslist as $id => $files) {
if (in_array($folder, $files['folders'])) {
$docs[] = $id;
}
}
return $docs;
}
阵列是:
foreach ($list[$i]->category as $cat) {
$folders[] = $cat->label;
}
$folderslist[$i] = array(
'name' => $foldername,
'authorname' => $authorname,
'authoremail' => $authoremail,
'lastupdated' => $lastupdated,
'fid' => $fid
);
$fileslist[] = array(
'name' => $name,
'authorname' => $authorname,
'authoremail' => $authoremail,
'lastupdated' => $lastupdated,
'folders' => $folders,
'id' => $id,
'type' => $list[$i]->extensionElements[0]->text,
);
用于文档列表的Google Docs API的XML是@ http://code.google.com/apis/documents/docs/3.0/developers_guide_protocol.html#ListDocs(注意类别只是文件夹名称)。
任何想法如何阻止文件出现在该文件夹名称的所有实例中,并且只是在正确的文件夹中?
答案 0 :(得分:1)
修正了它:)
/**
* Gets a list of 'internal' IDs of docs within a certain folder
* @global Mixed $fileslist
* @param ID $folder The internal ID of the folder
* @return Array
*/
function getDocumentsInFolder($folder) {
global $fileslist, $folderslist;
// Work out the folder ID
$fid = $folderslist[$folder]['fid'];
$docs = array();
foreach ($fileslist as $id => $files) {
if ($files['fid'] == $fid) {
$docs[] = $id;
}
}
return $docs;
}
文件清单返回:
<link rel="http://schemas.google.com/docs/2007#parent" type="application/atom+xml" href="https://docs.google.com/feeds/default/private/full/folder%3A12345" title="AFolderName"/>
其中包含文件夹ID,我能够将其存储在文档列表中然后进行比较。