![](/img/trans.png)
[英]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.