简体   繁体   中英

Google Drive API - get unique list of files in folder

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.

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

在此处输入图片说明

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"

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?

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

?>

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM