[英]Google_Http_Request to Google-Drive-API get readable data for response body
[英]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”中)。
为了解决这个问题,我在循环中添加了方法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”对象。
我是否缺少某些东西,或者这是某个地方的错误?
PS我测试了下一个链接的查询,它的工作原理:
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));
但是问题仍然存在...
呵呵,我发现问题出在哪里!
在upload_file()函数中,我的上传过程很奇怪...我认为这部分有问题:
$this->client->setDefer(true);
现在,它可以完美运行了!
希望以后对您有所帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.