我为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会返回错误。 (或者它会创建新文件夹但文件不会在同一文件夹中#34; folder1")。
为了解决这个问题,我在循环中添加了方法listChildrens(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对象。如果找到文件夹WAS,则返回" Google_Http_Request"对象
我错过了什么,或者这是某处的错误?
P.S。 我在下一个链接上测试了查询,它可以工作:
https://developers.google.com/drive/v2/reference/children/list#try-it
请帮助我 - 我很累。
提前致谢!
更新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));
但问题仍然存在......
答案 0 :(得分:0)
在upload_file()函数中我有奇怪的上传过程......我认为这部分是有问题的:
$this->client->setDefer(true);
现在它完美无缺!
我希望以后会对某人有所帮助!