我在使用Google Drive API查找文件时遇到问题。我设置了一个服务帐户,因此不确定这是否会产生影响。我的代码在下面,我现在得到的是undefined
返回。我还想在特定文件夹中搜索,但似乎无法在任何地方找到此选项?
// Check File exists
drive.files.list({
auth: jwtClient,
spaces: 'drive',
q: "name='liverpool_away.xlsx'",
pageSize: 10,
fields: "nextPageToken, files(id, name)"
}, function(err, response) {
if (err) {
console.log('The API returned an error: ' + err);// outputs The API returned an error: TypeError: Cannot read property 'length' of undefined
return;
}
var files = response.files;
console.log("Files: " + files); // outputs undefined
if (files.length == 0) {
console.log('No files found.');
} else {
console.log('Files:');
for (var i = 0; i < files.length; i++) {
var file = files[i];
console.log('%s (%s)', file.name, file.id);
}
}
});