简体   繁体   English

通过Drive API访问文件夹中的文件?

[英]Accessing files in a folder via Drive API?

I am trying to access some files from my Google Drive, via the Drive API. 我正在尝试通过Drive API从我的Google Drive访问一些文件。 I followed the tutorial here , to do so in Javascript. 我按照此处的教程进行操作,以Java语言实现。 Now, simply calling the function listFiles() works correctly, and prints all the files in my drive, along with their ID's. 现在,只需调用函数listFiles()正常工作,并打印驱动器中的所有文件及其ID。

But, I want to access all the files found in certain folders. 但是,我想访问某些文件夹中的所有文件。 Looking online, the drive API has such a function called retrieveAllFilesInFolder(folderId, callback) 在线查看时,驱动器API具有一个称为retrieveAllFilesInFolder(folderId, callback)的函数。

It is defined as follows: 定义如下:

function retrieveAllFilesInFolder(folderId, callback) {
  var retrievePageOfChildren = function(request, result) {
    request.execute(function(resp) {
      result = result.concat(resp.items);
      var nextPageToken = resp.nextPageToken;
      if (nextPageToken) {
        request = gapi.client.drive.children.list({
          'folderId' : folderId,
          'pageToken': nextPageToken
        });
        retrievePageOfChildren(request, result);
      } else {
        callback(result);
      }
    });
  }
  var initialRequest = gapi.client.drive.children.list({
      'folderId' : folderId
    });
  retrievePageOfChildren(initialRequest, []);
}

When, I call the code in my local server (passing in a string ID of a folder), I get the following error: quickstart.html:73 Uncaught TypeError: Cannot read property 'list' of undefined , implying there are no children of this folder. 当我在本地服务器中调用代码(传递文件夹的字符串ID)时,出现以下错误: quickstart.html:73 Uncaught TypeError: Cannot read property 'list' of undefined ,这意味着没有子级的这个文件夹。 I know this to be false. 我知道这是错误的。 Is there a particular reason that this is happening. 是否有发生这种情况的特殊原因。

您可以通过Google Developers网站直接在此处进行操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何查看Google Drive API的文件和文件夹? - How to see files and folder of google drive API? 使用驱动器api搜索文件夹内的文件 - Search for files inside of a folder using drive api 通过 API 使用服务帐户访问共享的 Google Drive 文件夹 - Accessing shared Google Drive folder using service account through API 通过 HTML 表单扫描 Google Drive 文件夹中的文件 - Scan files in a Google Drive folder via an HTML form Google Drive API中父文件夹下的文件和文件夹列表 - List of files and folders under a parent folder from Google Drive API Google Drive API v3 查找文件夹和子项中的所有文件 - Google Drive API v3 find all files in folder and children google drive api - copyfile 仅在访问驱动器中所有文件的权限下工作(但需要复制) - google drive api - copyfile working only with permission for accessing all files in drive (but jst need to copy) 使用 drive.files.list 时,Google Drive API 找不到我的文件夹 - Google drive API does not find my folder when using the drive.files.list 使用Google Drive API导航到文件夹 - Navigate to folder with Google Drive API 使用 Google Drive API v3 中的 drive.files.copy 转换,通过 nodejs 使用 API 将 Word 文档转换为 Google 文档 - convert a Word doc into a Google doc using the API via nodejs using drive.files.copy convert in v3 of Google Drive API
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM