Google Drive API -子列表返回"Google_Http_Request"而不是“Go


Google Drive API - children list returns "Google_Http_Request" instead "Google_Service_Drive_ChildList"

我下载了最新的PHP Google Drive API sdk。我想在特定文件夹和子文件夹中上传几个文件。例如:

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

我已经用

方法构建了一个类
upload_file(local_path, remote_desination_folder)...

在这个方法中我有:

paths = explode("/", remote_destination_folder);

然后

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

(这是伪代码…)

这段代码的问题是因为Google API返回一个错误,如果我试图创建一个名称已经存在的文件夹。(或者它将创建一个新文件夹,但文件将不在同一个文件夹"folder1"中)。

为了解决这个问题,我在循环中添加了listchildren (folderId, folder_name)方法。这个函数看起来像这样:

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);
}

现在,我最不明白的事情是:

如果没有找到文件夹,它返回Google_Service_Drive_ChildList对象,该对象具有空项数组。如果文件夹被找到,它返回"Google_Http_Request"对象。

我错过了什么或这是bug某处?

注:我在下一个链接上测试了查询,它有效:

https://developers.google.com/drive/v2/reference/children/list试一试

请帮帮我,我已经很累了。

提前感谢!

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

嗨了。

我刚刚尝试了像这样调用文件/列表:

$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));

哈,我找到问题所在了!

在upload_file()函数中,我有奇怪的上传过程…我想这部分是有问题的:

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

现在它工作完美!

我希望这对以后的人有帮助!