Node.js google drive列出公共共享文件夹中的文件
我有一个经过验证的google客户端,我想列出其他人公用文件夹中的文件(我认为共享或不共享的文件夹是不相关的,因为它是公用的) 这是我在NodeJS中的代码Node.js google drive列出公共共享文件夹中的文件,node.js,google-drive-api,Node.js,Google Drive Api,我有一个经过验证的google客户端,我想列出其他人公用文件夹中的文件(我认为共享或不共享的文件夹是不相关的,因为它是公用的) 这是我在NodeJS中的代码 const drive = google.drive({ version: 'v3', auth }); let fconf = {}; fconf.maxResults = 10; fconf.orderBy = "createdTime"; fconf.driveId = "xy
const drive = google.drive({ version: 'v3', auth });
let fconf = {};
fconf.maxResults = 10;
fconf.orderBy = "createdTime";
fconf.driveId = "xyz-badfd134343example";
fconf.includeItemsFromAllDrives = true;
fconf.q = "application/vnd.google-apps.spreadsheet";
fconf.supportsTeamDrives = true;
fconf.corpa = "drive";
fconf.supportsAllDrives = true;
drive.files.list(fconf, function(e,d)
{
console.log("e,d",e,d);
});
}
注意:文档中没有“folderId”选项:-只有一个driveId选项
虽然我将corpa设置为“drive”和drive Id,但是我得到了以下错误
{ Error: The driveId parameter must be specified if and only if corpora is set to drive.
at Gaxios.<anonymous> (/home/ubuntu/c/node_modules/gaxios/build/src/gaxios.js:73:27)
at Generator.next (<anonymous>)
at fulfilled (/home/ubuntu/c/node_modules/gaxios/build/src/gaxios.js:16:58)
at <anonymous>
at process._tickDomainCallback (internal/process/next_tick.js:228:7)
response:
{ config:
{ url: 'https://www.googleapis.com/drive/v3/files?driveId=examplexyz&includeItemsFromAllDrives=true&corpa=drive&supportsAllDrives=true',
method: 'GET',
paramsSerializer: [Function],
headers: [Object],
params: [Object],
validateStatus: [Function],
responseType: 'json' },
data: { error: [Object] },
headers:
{ 'alt-svc': 'quic=":443"; ma=2592000; v="46,43",h3-Q048=":443"; ma=2592000,h3-Q046=":443"; ma=2592000,h3-Q043=":443"; ma=2592000',
'cache-control': 'private, max-age=0',
connection: 'close',
'content-encoding': 'gzip',
'content-type': 'application/json; charset=UTF-8',
date: 'Thu, 24 Oct 2019 00:38:10 GMT',
expires: 'Thu, 24 Oct 2019 00:38:10 GMT',
server: 'GSE',
'transfer-encoding': 'chunked',
vary: 'Origin, X-Origin',
'x-content-type-options': 'nosniff',
'x-frame-options': 'SAMEORIGIN',
'x-xss-protection': '1; mode=block' },
status: 403,
statusText: 'Forbidden' },
config:
{ url: 'https://www.googleapis.com/drive/v3/files?driveId=examplexyz&includeItemsFromAllDrives=true&corpa=drive&supportsAllDrives=true',
method: 'GET',
paramsSerializer: [Function],
headers:
{ 'Accept-Encoding': 'gzip',
'User-Agent': 'google-api-nodejs-client/0.7.2 (gzip)',
Authorization: 'Bearer something',
Accept: 'application/json' },
params:
{ driveId: 'examplexyz',
includeItemsFromAllDrives: true,
corpa: 'drive',
supportsAllDrives: true },
validateStatus: [Function],
responseType: 'json' },
code: 403,
errors:
[ { domain: 'global',
reason: 'teamDriveIdRequiresTeamDriveCorpora',
message: 'The driveId parameter must be specified if and only if corpora is set to drive.' } ] } undefined
close the queue { success: true }
{错误:当且仅当corpora设置为drive时,必须指定driveId参数。
在Gaxios上。(/home/ubuntu/c/node_modules/Gaxios/build/src/Gaxios.js:73:27)
在Generator.next()处
完成时(/home/ubuntu/c/node_modules/gaxios/build/src/gaxios.js:16:58)
在
在进程中。_tickDomainCallback(internal/process/next_tick.js:228:7)
答复:
{config:
{url:'https://www.googleapis.com/drive/v3/files?driveId=examplexyz&includeItemsFromAllDrives=true&corpa=drive&supportsAllDrives=true',
方法:“GET”,
参数化器:[函数],
标题:[对象],
参数:[对象],
validateStatus:[函数],
responseType:'json'},
数据:{错误:[对象]},
标题:
{'alt svc':'quic=“:443”;ma=2592000;v=“46,43”,h3-Q048=“:443”;ma=2592000,h3-Q046=“:443”;ma=2592000,h3-Q043=“:443”;ma=2592000”,
“缓存控制”:“专用,最大年龄=0”,
连接:“关闭”,
“内容编码”:“gzip”,
“内容类型”:“应用程序/json;字符集=UTF-8”,
日期:“2019年10月24日星期四00:38:10 GMT”,
到期日期:“2019年10月24日星期四00:38:10 GMT”,
服务器:“GSE”,
“传输编码”:“分块”,
更改:“原点,X原点”,
“x-content-type-options”:“nosniff”,
“x-frame-options”:“SAMEORIGIN”,
“x-xss-protection”:“1;模式=块”},
现状:403,
statusText:'禁止'},
配置:
{url:'https://www.googleapis.com/drive/v3/files?driveId=examplexyz&includeItemsFromAllDrives=true&corpa=drive&supportsAllDrives=true',
方法:“GET”,
参数化器:[函数],
标题:
{“接受编码”:“gzip”,
“用户代理”:“google api nodejs客户端/0.7.2(gzip)”,
授权:'持有人某物',
接受:'application/json'},
参数:
{driveId:'examplexyz',
IncludeItemsFlomallDrive:正确,
科尔帕:“开车”,
supportsAllDrives:true},
validateStatus:[函数],
responseType:'json'},
代码:403,
错误:
[{域:'全局',
原因:“TeamDriveIDRequestTeamDriveCorpora”,
消息:“当且仅当corpora设置为drive时,必须指定driveId参数。”}]}未定义
关闭队列{success:true}
- 您想从公共共享文件夹中检索文件列表。
- 您只想检索电子表格文件
- 您希望通过Node.js使用googleapis实现这一点
- 您已经能够使用驱动器API的files.list方法检索文件列表
- 在此修改中,为了从公共共享文件夹检索文件列表,将修改脚本的搜索查询。
- 在父文件夹中搜索“folderId”将返回文件夹中的文件列表
- 如果要检索公共共享文件夹中所有文件的文件列表,请使用parents中的
'${folderId}'作为搜索查询
- 在上面修改的脚本中,当文件夹不是您的且不是公开共享的时,无法从该文件夹中检索文件列表。请小心这个
一流的反应。我现在收到200个响应,不幸的是data.files是一个空数组[]。有什么想法吗?可公开使用的驱动器url为:@user1709076谢谢您的回复。给您带来不便,我深表歉意。当我检查您在parents中查询“folderId”时提供的文件夹时,发现所有文件的mimeType都是
text/csv
。因此,请在parents和mimeType中尝试查询fconf.q=`${folderId}',text/csv`
orfconf.q=`parents`中的${folderId}
.yes,正在尝试fconf.q='${folderId}'在父文件夹中
-我不知道为什么会得到一个空文件数组数据:{kind:'drive#fileList',incompleteSearch:false,files:[]}-无论我选择哪个公用文件夹,似乎都是一个空文件数组,例如:fconf.q='0b3d5a94e071mfjn6s19megzzyi1hwhnfeflpwvdqs3rmwxhnhjehhmdu91wwwwwjdcn1u'在父级中
@用户1709076谢谢您的回复。我必须再次道歉。关于文件夹ID,发现0b3d5a94e071mfjn6s19megzzyi1hwhnfeflpwvdqs3rmwxhnhjehhmdu91wwwwwwwjdcn1u
与您评论的1IRg7eNuHNc7wmLkbpk_uumnwc-MNtovLd
的初始文件夹ID不同。对于当前文件夹ID,所有文件都是文件夹。因此,您可以使用父级中的fconf.q=
'${folderId}'检索文件列表代码>。但我不确定你现在的剧本。因此,我将您提供的文件夹ID的示例脚本添加到我的答案中。你能确认一下吗?谢谢。是的,您是对的,通过使用我可以查看其他人公开可用的驱动器文件-尽管我不理解,因为在接受时权限要求查看“您拥有的所有文件”。该方案是方案中最不激进的政策。谢谢你的好意回答这个问题,我愿意接受你的回答。
const folderId = "###"; // Please set the folder ID of the publicly shared folder.
const drive = google.drive({ version: "v3", auth });
let fconf = {};
fconf.maxResults = 10;
fconf.orderBy = "createdTime";
fconf.q = `'${folderId}' in parents and mimeType = 'application/vnd.google-apps.spreadsheet'`;
drive.files.list(fconf, function(error, response) {
if (error) {
console.log(error);
} else {
console.log(response.data);
}
});
const drive = google.drive({ version: "v3", auth });
const folderId = "0B3d5a94e071mfjN6S19MeGZZYi1hWHNfeFlPWVdqS3RMWXhXMnhJeHhmdU91WWlwWjdCN1U";
let fconf = {};
fconf.maxResults = 10;
fconf.orderBy = "createdTime";
fconf.q = `'${folderId}' in parents`;
drive.files.list(fconf, function(error, response) {
if (error) {
console.log(error);
} else {
console.log(response.data);
}
});