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

时间:2022-02-16 07:08:21

I'm using the PHP beta library for Google drive. I've got a list of files in a folder, but it's duplicating the file names a bunch of times.

我正在将PHP beta库用于Google驱动器。我有一个文件夹中的文件列表,但它复制了文件名很多次。

Here is my drive folder. You can see there are only 7 files:

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

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

But when I list using the library (titles only) I get this.

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

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"

数组[39] 0:“cantact”1:“bsn”2:“豪华”3:“豪华”4:“豪华”5:“postum”6:“炸药”7:“炸药”8:“炸药”9 :“炸药”10:“炸药”11:“炸药”12:“炸药”13:“炸药”14:“炸药”15:“炸药”16:“ecoamour”17:“豪华”18:“ecoarmour”19 :“hex.pdf”20:“hex”21:“炸药”22:“土拨鼠”23:“炸药”24:“土拨鼠”25:“土拨鼠”26:“炸药”27:“炸药”28:“土拨鼠” “29:”炸药“30:”炸药“31:”炸药“32:”炸药“33:”炸药“34:”evpro“35:”evpro“36:”evpro“37:”Untitled“38:”evpro “

Obviously this is because of archived/revisions or something similar. But how can I get a list of the files that mimics what I see in Drive like above?

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

<?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 个解决方案

#1


Figured it out. Needed to add and trashed=false to the query

弄清楚了。需要向查询添加和trashed = false

#1


Figured it out. Needed to add and trashed=false to the query

弄清楚了。需要向查询添加和trashed = false