简体   繁体   中英

Google Drive API - children list returns “Google_Http_Request” instead “Google_Service_Drive_ChildList”

I downloaded the most recent Google Drive API sdk for PHP. I want to upload couple of files in particular folders and sub-folders. For example:

item 1: folder1/folderA/file.png
item 2: folder1/folderB/file.png
item 3: folder1/folderC/file.png

I had built a class with the method

upload_file(local_path, remote_desination_folder)...

Inside that method I have:

paths = explode("/", remote_destination_folder);

and then

parent_id = 0; 
foreach(paths as path){
    parent_id = this->create_folder(path, parent_id); 
}

(This is pseudo code...)

Problem with this code is because Google API returns an error if I try to create a folder with name that already exists. (Or it will create new folder but then files would not be in same folder "folder1" ).

To fix this, I added method listChildrens(folderId, folder_name) in the loop. This function looks like this:

private function myListChildren(folderId,title)
{
    qstr = "title = 'title' and mimeType='application/vnd.google-apps.folder' and trashed=false";
    childs = this->service->children->listChildren(folderId,array('q' => qstr));
    echo "Searching for title in folderId query= qstr...\n";
    print_r(childs);
}

Now, the most strange thing that I can't understand:

if a folder was NOT found it returns Google_Service_Drive_ChildList object that has empty items array. If folder WAS found, it returns "Google_Http_Request" object.

Am I missing something or this is bug somewhere?

PS I tested query on the next link and it works:

https://developers.google.com/drive/v2/reference/children/list#try-it

Please help me - I am quite exhausted.

Thanks in advance!

UPDATE 2014-08-14 09:24 (UTC+1):

Hi again.

I just tryed with files/list call like this:

$qstr = "title = '$title' and mimeType='application/vnd.google-apps.folder' AND trashed = false AND '$folderId' in parents ";
$childs = $this->service->children->listChildren($folderId,array('q'         => $qstr));

But the problem stays...

Huh, I found where was problem!!

In the upload_file() function I had strange upload process... I assume this part was problematic:

$this->client->setDefer(true);

Now it works perfectly!

I hope this will help to someone later!

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