[英]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. 我下载了最新的PHP的Google Drive API sdk。 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. 这段代码的问题是因为,如果我尝试创建一个名称已经存在的文件夹,则Google API返回错误。 (Or it will create new folder but then files would not be in same folder "folder1" ). (或者它将创建新文件夹,但是文件将不在同一文件夹“ folder1”中)。
To fix this, I added method listChildrens(folderId, folder_name) in the loop. 为了解决这个问题,我在循环中添加了方法listChildrens(folderId,folder_name)。 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. 如果未找到文件夹,则返回具有空项目数组的Google_Service_Drive_ChildList对象。 If folder WAS found, it returns "Google_Http_Request" object. 如果找到文件夹WAS,则返回“ Google_Http_Request”对象。
Am I missing something or this is bug somewhere? 我是否缺少某些东西,或者这是某个地方的错误?
PS I tested query on the next link and it works: PS我测试了下一个链接的查询,它的工作原理:
https://developers.google.com/drive/v2/reference/children/list#try-it 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): 更新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: 在upload_file()函数中,我的上传过程很奇怪...我认为这部分有问题:
$this->client->setDefer(true);
Now it works perfectly! 现在,它可以完美运行了!
I hope this will help to someone later! 希望以后对您有所帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.