嘿伙计们,我在使用 Google Drive API 返回某些文件时遇到问题。
function retrieve_all_files($service,$parameters) {
$result = array();
$pageToken = NULL;
do {
try {
$parameters = array();
if ($pageToken) {
$parameters['pageToken'] = $pageToken;
}
$files = $service->files->listFiles($parameters);
$result = array_merge($result, $files->getItems());
$pageToken = $files->getNextPageToken();
} catch (Exception $e) {
print "An error occurred: " . $e->getMessage();
$pageToken = NULL;
}
} while ($pageToken);
return $result;
}
$format = DateTime::RFC3339;
$date = new DateTime('now');
$date->modify('-3 days');
$date_str = $date->format($format);
$parameters = array('q' => "trashed = false and modifiedDate < '$date_str'");
echo count(retrieve_all_files($service, $parameters));
出于某种原因,参数选项返回所有文件,而不是根据特定条件返回的文件。