1

PHPを使用してフォルダーのリストを取得し、次にGoogleドキュメントからドキュメントを取得します(2つのAPIリクエスト)。

フォルダのリストを取得すると、フォルダIDを取得できます。これで問題ありません。

ただし、ドキュメントのリストを取得すると、カテゴリが返され、これらにはフォルダの名前のみが含まれます。

同じ名前のフォルダが2つあり、同じ名前のフォルダがあるため、コードがこれらのフォルダのドキュメントをマージしているため、問題が発生します。

フォルダ内のドキュメントのリストを取得するために使用する関数:

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

ドキュメントのリスト用のGoogleDocsAPIのXMLは、@ http://code.google.com/apis/documents/docs/3.0/developers_guide_protocol.html#ListDocsです(カテゴリが単なるフォルダ名であることに注意してください)。

そのフォルダ名のすべてのインスタンスで、適切なフォルダだけにファイルが表示されないようにする方法はありますか?

4

1 に答える 1

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が含まれているので、これをドキュメントリストに保存して比較することができました。

于 2010-07-28T09:33:02.830 に答える