我正在尝试通过 setParents 更新 Google_DriveFile 对象的父对象,然后在文件上调用更新。(所以我试图将文件移动到不同的文件夹。)从 API 文档(https://developers.google.com/drive/v2/reference/files/update)看来这是可能的,我猜我只是在做错事。任何帮助,将不胜感激。
除了移动文件外,一切都很好。更新调用的返回与原始父级(不是新父级)相同。
$files = $service->files->listFiles(array('q' => "'" . Configure::read('GoogleDrive.search_directory_id') . "' in parents"));
//debug($files); exit;
if (!empty($files->items)){
foreach ($files->items as $file){
if ($file->mimeType != 'image/jpeg'){
// move to processed, do nothing else
}else{
if (!empty($file->downloadUrl)){
$request = new Google_HttpRequest($file->downloadUrl, 'GET', null, null);
$httpRequest = Google_Client::$io->authenticatedRequest($request);
if ($httpRequest->getResponseHttpCode() == 200) {
//file_put_contents(WWW_ROOT . 'drive_downloads' . DS . strtolower($file->title), $httpRequest->getResponseBody());
echo 'Writing file: ' . strtolower($file->title);
} else {
echo 'Couldnt get this file!: ' . $file->title;
}
}
}
// let's move the file to the processed folder here...
$newParent = new Google_ParentReference(Configure::read('GoogleDrive.will_processed_directory_id'));
$file->setParents(array($newParent));
$service->files->update($file->id, $file);
}
}