Google Docs API 文档列表和两个同名文件夹

发布于 2024-09-11 12:49:58 字数 1590 浏览 2 评论 0原文

我使用 PHP 获取文件夹列表,然后获取 Google Docs 中的文档(两个 API 请求)。

获取文件夹列表,我可以获得它们的folderID,这很好。

但是,当获取文档列表时,它会返回类别,并且这些类别仅包含文件夹的名称。

我的问题存在是因为我有两个同名的文件夹,并且我的代码正在合并这些文件夹中的文档,因为它们具有相同的名称。

我用来获取文件夹内文档列表的函数:

/**
 * 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(请注意类别只是文件夹名称)。

有什么想法如何阻止文件出现在该文件夹名称的所有实例中,并且仅出现在其正确的文件夹中?

I use PHP to get a list of folders, and then documents from Google Docs (two API requests).

Getting a list of the folders, I can get their folderID, which is fine.

However, when getting a list of documents, it returns categories, and these only contain the name of the folder.

My problem exists because I have two folders with the same name, and my code is merging the documents from these, because they have the same name.

The function I use to get a list of the documents within the folder:

/**
 * 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;
}

And the arrays are:

    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,
    );

The XML the Google Docs API for the list of documents is @ http://code.google.com/apis/documents/docs/3.0/developers_guide_protocol.html#ListDocs (Note how the categories are just folder names).

Any ideas how to stop files appearing in all instances of that folder name, and just in their proper folder?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

手长情犹 2024-09-18 12:49:58

已修复:)

/**
 * 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,我能够将其存储在文档列表中然后进行比较。

Fixed it :)

/**
 * 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;
}

The document list returns:

 <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"/>

Which contains the folder ID, I was able to store this in the document list and then compare.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文