找不到文件 google 驱动器 API
File not found google drive API
我正在尝试列出文件并从中删除一些文件,但是更新 API 抛出错误 找不到文件。尽管 list API 返回结果并且我将相同的文件 ID 传递给更新 API.
drive.files.list(
{
q:
"mimeType='application/zip' and name = '" +
prevFileName +
"' and '" +
parent +
"' in parents",
fields: "files(kind,id,name,mimeType,teamDriveId,parents,createdTime)",
corpora: "drive",
includeTeamDriveItems: true,
supportsTeamDrives: true,
teamDriveId: teamDriveId
},
(err, res) => {
if (err) {
console.log("Error listing files ", err.message);
} else {
const prevFiles = res && res.data && res.data.files;
console.log("prevFiles : ", prevFiles);
if (prevFiles && prevFiles[0] && prevFiles[0].name === prevFileName) {
drive.files.update(
{
fileId: prevFiles[0].id
},
{ resource: { trashed: true } },
(err, result) => {
if (!err) {
console.log("Prev file successfully deleted : ", result);
resolve("File upload SuccessFully: ", file.data);
} else {
console.error("Error removing prev file :: ", err);
}
}
);
}
}
}
);
我在这里得到一个文件,其中包含一些 json 响应
[ { kind: 'drive#file',
id: 'ksnadoasjndajn12n1n212',
name: 'xxx_x_x.zip',
mimeType: 'application/zip',
parents: [ 'xxxx-sandadaadakmke' ],
createdTime: '2021-07-14T06:12:11.169Z',
teamDriveId: 'xxxonaijsojxxx' } ]
但是当我在更新 API 中传递这个 id 时它抛出错误。
我的授权范围是
var SCOPES = [
"https://www.googleapis.com/auth/drive",
"https://www.googleapis.com/auth/drive.appdata",
"https://www.googleapis.com/auth/drive.file",
"https://www.googleapis.com/auth/drive.readonly",
"https://www.googleapis.com/auth/drive.metadata.readonly",
"https://www.googleapis.com/auth/drive.metadata",
"https://www.googleapis.com/auth/drive.photos.readonly"
];
请帮我解决这个问题。
谢谢。
由于您的 drive.files.list
请求包含 includeTeamDriveItems: true
和 supportsTeamDrives: true
,您应该为 drive.files.update
指定相应的选项
默认情况下 supportsAllDrives
设置为 false,除非您明确将其设置为 true
。
因此,将找不到位于团队驱动器上的文件。
注意:supportsTeamDrives
已弃用,将supportsAllDrives
设置为true
即可。
我正在尝试列出文件并从中删除一些文件,但是更新 API 抛出错误 找不到文件。尽管 list API 返回结果并且我将相同的文件 ID 传递给更新 API.
drive.files.list(
{
q:
"mimeType='application/zip' and name = '" +
prevFileName +
"' and '" +
parent +
"' in parents",
fields: "files(kind,id,name,mimeType,teamDriveId,parents,createdTime)",
corpora: "drive",
includeTeamDriveItems: true,
supportsTeamDrives: true,
teamDriveId: teamDriveId
},
(err, res) => {
if (err) {
console.log("Error listing files ", err.message);
} else {
const prevFiles = res && res.data && res.data.files;
console.log("prevFiles : ", prevFiles);
if (prevFiles && prevFiles[0] && prevFiles[0].name === prevFileName) {
drive.files.update(
{
fileId: prevFiles[0].id
},
{ resource: { trashed: true } },
(err, result) => {
if (!err) {
console.log("Prev file successfully deleted : ", result);
resolve("File upload SuccessFully: ", file.data);
} else {
console.error("Error removing prev file :: ", err);
}
}
);
}
}
}
);
我在这里得到一个文件,其中包含一些 json 响应
[ { kind: 'drive#file',
id: 'ksnadoasjndajn12n1n212',
name: 'xxx_x_x.zip',
mimeType: 'application/zip',
parents: [ 'xxxx-sandadaadakmke' ],
createdTime: '2021-07-14T06:12:11.169Z',
teamDriveId: 'xxxonaijsojxxx' } ]
但是当我在更新 API 中传递这个 id 时它抛出错误。 我的授权范围是
var SCOPES = [
"https://www.googleapis.com/auth/drive",
"https://www.googleapis.com/auth/drive.appdata",
"https://www.googleapis.com/auth/drive.file",
"https://www.googleapis.com/auth/drive.readonly",
"https://www.googleapis.com/auth/drive.metadata.readonly",
"https://www.googleapis.com/auth/drive.metadata",
"https://www.googleapis.com/auth/drive.photos.readonly"
];
请帮我解决这个问题。 谢谢。
由于您的 drive.files.list
请求包含 includeTeamDriveItems: true
和 supportsTeamDrives: true
,您应该为 drive.files.update
默认情况下 supportsAllDrives
设置为 false,除非您明确将其设置为 true
。
因此,将找不到位于团队驱动器上的文件。
注意:supportsTeamDrives
已弃用,将supportsAllDrives
设置为true
即可。