Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/254.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google Drive Api PHP删除多个文件_Php_File_Google Drive Api_Delete File - Fatal编程技术网

Google Drive Api PHP删除多个文件

Google Drive Api PHP删除多个文件,php,file,google-drive-api,delete-file,Php,File,Google Drive Api,Delete File,救命啊 在使用php删除google drive api中的多个文件时遇到问题 我找到了一个用于批量删除的链接,但它使用python。 我试图用php重新创建它,但它不起作用。 有人帮我做我想做的事吗 方法1: <?php include_once('variables.php'); $service = connectGoogleDrive(); $optParams = array( 'pageSize' => 1000,

救命啊

在使用php删除google drive api中的多个文件时遇到问题

我找到了一个用于批量删除的链接,但它使用python。 我试图用php重新创建它,但它不起作用。 有人帮我做我想做的事吗

方法1:

<?php
    include_once('variables.php');
    $service = connectGoogleDrive();

    $optParams = array(
        'pageSize' => 1000,
        'fields' => 'nextPageToken, files(id, name, webViewLink)'
    );
    $results = $service->files->listFiles($optParams);

    $service->getClient()->setUseBatch(true);
    $batch = $service->createBatch();
    foreach ($results->getFiles() as $file) {
        $request = $service->files->delete($file->getId());
        $batch->add($request);
    }
    $results = $batch->execute();
    foreach ($results as $result) {
        if ($result instanceof Google_Service_Exception) {
            // Handle error
            printf($result);
        }
    }
    $service->getClient()->setUseBatch(false);

?>
编辑2
一开始没有问题。遗憾的是,我忘记了最多1000个文件,这就是我认为有错误的原因。我希望能立即删除文件。

没有错误,我的代码可以正常工作哈哈哈

$client->setUseBatch(true);
/************************************************
 We then create a batch, and add each query we
 want to execute with keys of our choice - these
 keys will be reflected in the returned array.
************************************************/
$batch = $service->createBatch();
$optParams = array('filter' => 'free-ebooks');
$req1 = $service->volumes->listVolumes('Henry David Thoreau', $optParams);
$batch->add($req1, "thoreau");
$req2 = $service->volumes->listVolumes('George Bernard Shaw', $optParams);
$batch->add($req2, "shaw");
/************************************************
  Executing the batch will send all requests off
  at once.
 ************************************************/
$results = $batch->execute();