首页 > 解决方案 > Google Drive API Search for folders

问题描述

I am trying to get a list of folders so that I can do a search for files within all subfolders. I am using this post (alternative 3) as a reference https://stackoverflow.com/a/41741521/1485815

My query is like this (I have tried mimetype and mimeType in the query)

    $optParams = array(
    'pageSize' => 1000
        ,'fields' => 'nextPageToken, files(contentHints/thumbnail,fileExtension,iconLink,id,name,size,thumbnailLink,webContentLink,webViewLink,mimeType,parents, kind, trashed, owners, modifiedTime)'
        ,'q' => "mimeType=application/vnd.google-apps.folder"
       );                

    $service = new \Google_Service_Drive($this->GoogleClient);
    $results = $service->files->listFiles($optParams);

I am authenticated fine, but this query gives an error with the following details

 "error": {
  "errors": [
   {
    "domain": "global",
    "reason": "invalid",
    "message": "Invalid Value",
    "locationType": "parameter",
    "location": "q"
   }
  ],
  "code": 400,
  "message": "Invalid Value"
 }

}

标签: google-drive-api

解决方案


  • 您想使用带有 PHP 的 googleapis 从 Google Drive 中检索文件夹列表。
  • 您已经能够使用 Drive API。
  • 你想知道你的问题的原因Invalid Value

修改后的脚本:

从:
,'q' => "mimeType=application/vnd.google-apps.folder"
至:
,'q' => "mimeType='application/vnd.google-apps.folder'"

或者

,'q' => 'mimeType="application/vnd.google-apps.folder"'
  • '请用和括起 mimeType 的值"

参考:


推荐阅读