Google Drive API - 获取文件夹中唯一的文件列表

时间:2015-05-08 14:03:14

标签: php google-drive-api

我正在将PHP beta库用于Google云端硬盘。我有一个文件夹中的文件列表,但它多次重复文件名。

这是我的驱动器文件夹。您可以看到只有7个文件:

enter image description here

但是当我列出使用该库(仅限标题)时,我得到了这个。

Array[39] 0:"cantact" 1:"bsn" 2:"posh" 3:"posh" 4:"posh" 5:"postum" 6:"dynamite" 7:"dynamite" 8:"dynamite" 9:"dynamite" 10:"dynamite" 11:"dynamite" 12:"dynamite" 13:"dynamite" 14:"dynamite" 15:"dynamite" 16:"ecoamour" 17:"posh" 18:"ecoarmour" 19:"hex.pdf" 20:"hex" 21:"dynamite" 22:"earthtreks" 23:"dynamite" 24:"earthtreks" 25:"earthtreks" 26:"dynamite" 27:"dynamite" 28:"earthtreks" 29:"dynamite" 30:"dynamite" 31:"dynamite" 32:"dynamite" 33:"dynamite" 34:"evpro" 35:"evpro" 36:"evpro" 37:"Untitled" 38:"evpro"

显然这是因为存档/修订或类似的东西。但是,如何获得模仿我在上面的驱动器中看到的文件列表?

<?php

require_once "/var/www/belts/modules/admin.php";
require_once "/var/www/api/googleDriveAPI.php";

$drive = new GoogleDrive();

// contracts folder
$folderId = "{{folder id}}";
// get file list
$files = $drive->service->files->listFiles([
    "q" => "'$folderId' in parents"
]);
// unique array of titles
$titles = [];
foreach ($files->getItems() as $file) {
    $titles[] = $file->title;
}
//$titles = array_unique($titles);

echo json_encode($titles);

?>

1 个答案:

答案 0 :(得分:1)

想出来。需要将and trashed=false添加到查询