我有一个经过身份验证的google客户,我想列出其他人的公用文件夹中的文件(我认为共享的文件夹与否是不相关的,因为它是公用的)
这是我在NodeJS中的代码
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'选项:https://developers.google.com/drive/api/v3/reference/files/list-只是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 }
答案 0 :(得分:1)
如果我的理解是正确的,那么该修改如何?
'folderId' in parents
的搜索查询返回文件夹中的文件列表。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);
}
});
'${folderId}' in parents
作为搜索查询。如果我误解了您的问题,而这不是您想要的结果,我深表歉意。
将您提供的文件夹ID用于脚本时,以下脚本如何?在这种情况下,在检索到的文件列表中可以看到8个文件夹。
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);
}
});