1

I want to transfer files from googledrive to my server to process them (my coworker can't put them directly on the server). It was working fine, it does not work anymore. I'm using the API V3 PHP library. All files are organized in directories that are in a given root. I list the content of my root quite easily, but I'm unable to get get the content of each subfolder. Here is my code:

function upload() {
    // Get the API client and construct the service object.
    $client = getClient();
    $service = new Google_Service_Drive($client);
    $list=$service->files->listFiles
            (array('q' => "mimeType='application/vnd.google-apps.folder' and name='MYROOT'",
                    'fields' => 'nextPageToken, files(id, name)'));
    $publicistRoot=$list->getFiles();
    $publicistRoot=$publicistRoot[0];
    $publicistRootId=$publicistRoot->getId();
    $list=$service->files->listFiles
            (array('q' => "mimeType='application/vnd.google-apps.folder' and '$publicistRootId' in parents",
                  'fields' => 'nextPageToken, files(id, name)'));
    foreach($list->getFiles() as $folder) {
        // ***** I can list all subdirectories
        uploadFolder($service, $folder);
    }
}

function uploadFolder(&$service, &$folder) {
    $dir="$parentDir/".trim($folder->getName());
    mkdir($dir);
    $list=$service->files->listFiles
            (array('q' => "'".$folder->getId()."' in parents",
                    'fields' => 'nextPageToken, files(id, name)'));
    // ***** here, in $list, the field "nextPageTogen is set to NULL
    $toTransfer=$list->getFiles();        
    if (!count($toTransfer)) {
        // ***** there is no files here, although there are some on the google drive
        print("Le dossier '".$folder->getName()."' ne contient pas de fichier.\n");
    } else {
        foreach($toTransfer as $elt) {
            // ***** copy contents
        }
    }
}

Has anybody an idea ?

My thanks for your help

ejmbou
  • 11
  • 1
  • Based from this [thread](https://webapps.stackexchange.com/questions/40006/in-google-drive-is-there-a-way-to-search-files-located-in-a-particular-folder) (though it's quite old), Google Drive does not support searching within a specific folder. As referred with this SO post: https://stackoverflow.com/questions/24720075/how-to-get-list-of-files-by-folder-on-google-drive-api, you should be able to simply use [files/list](https://developers.google.com/drive/v2/reference/files/list) with a parent query **(but using v2)**. – abielita Nov 24 '17 at 16:13

0 Answers0