Node.js Google API、drive.files.list和仅返回子文件

Node.js Google API、drive.files.list和仅返回子文件,node.js,google-drive-api,google-api-nodejs-client,Node.js,Google Drive Api,Google Api Nodejs Client,我正在NodeJS中使用“”库,并试图返回当前指定文件夹中的文件和文件夹列表,但我发现drive.files.list返回用户已被授予读取权限的所有文件 我的目标是能够下载给定文件夹下的文件夹结构,然后NodeJS应用程序可以以有意义的方式使用该文件夹结构 我使用的代码如下: const fs = require('fs'); const google = require('googleapis'); const OAuth2 = google.auth.OAuth2; const key =

我正在NodeJS中使用“”库,并试图返回当前指定文件夹中的文件和文件夹列表,但我发现
drive.files.list
返回用户已被授予读取权限的所有文件

我的目标是能够下载给定文件夹下的文件夹结构,然后NodeJS应用程序可以以有意义的方式使用该文件夹结构

我使用的代码如下:

const fs = require('fs');
const google = require('googleapis');
const OAuth2 = google.auth.OAuth2;
const key = require('./key.json');

const jwtClient = new google.auth.JWT(
  key.client_email,
  null,
  key.private_key,
  ['https://www.googleapis.com/auth/drive'],
  null
);

const drive = google.drive({
  version: 'v3',
  auth: jwtClient
});

jwtClient.authorize(function (err, tokens) {
  if (err) {
    console.log(err);
    return;
  }

  // Make an authorized request to list Drive files.
  drive.files.list({
     includeRemoved: false,
     spaces: 'drive',
     fileId: 'the-file-id-of-the-folder'
  }, function (err, resp) {
    if (!err) {
        var i;
        var files = resp.files;
        for (i=0; i<files.length; i++) {
            if (files[i].mimeType !== 'application/vnd.google-apps.folder') {
                console.log('file: ' + files[i].name);
            } else {
                console.log('directory: ' + files[i].name);
            }
            console.log(files[i]);
        }
    } else {
        console.log('error: ', err);
    }
  });
});
const fs=require('fs');
const google=require('googleapis');
const OAuth2=google.auth.OAuth2;
const key=require('./key.json');
const jwtClient=new google.auth.JWT(
key.client_电子邮件,
无效的
密钥,私钥,
['https://www.googleapis.com/auth/drive'],
无效的
);
const drive=google.drive({
版本:“v3”,
auth:jwtClient
});
jwtClient.authorize(函数(错误、令牌){
如果(错误){
控制台日志(err);
返回;
}
//发出授权请求以列出驱动器文件。
drive.files.list({
包括:假,
空格:“驱动器”,
fileId:'文件夹的文件id'
},函数(err,resp){
如果(!err){
var i;
var files=resp.files;

对于(i=0;i进一步探索将导致“页面”,这表明在API的v3中还有“字段”和“q”参数,因此列表操作变为(ES6代码):

注意,有关其他元数据,请参见:

var fileId = '0B0gSXXXXXXXXXXXXXXXXb0hpaWM'
drive.files.list({
    includeRemoved: false,
    spaces: 'drive',
    fileId: fileId,
    fields: 'nextPageToken, files(id, name, parents, mimeType, modifiedTime)',
    q: `'${fileId}' in parents`
}, function (err, response) {
   // TODO handle response
});