Javascript 如何将文件或文件夹移动到google drive api中的其他文件夹?
我做了文档中的所有事情()。但这对我不起作用。我已对该脚本进行了一些更正:Javascript 如何将文件或文件夹移动到google drive api中的其他文件夹?,javascript,google-drive-api,Javascript,Google Drive Api,我做了文档中的所有事情()。但这对我不起作用。我已对该脚本进行了一些更正: window.gapi.client.drive.files.get({ fileId: fileId, fields: 'parents' }).then(res => { console.log(res) window.gapi.client.drive.files.update({ fileId: this.fil
window.gapi.client.drive.files.get({
fileId: fileId,
fields: 'parents'
}).then(res => {
console.log(res)
window.gapi.client.drive.files.update({
fileId: this.fileData.id,
addParents: folderId,
removeParents: res.result.parents[0],
fields: 'id, parents'
}).then(res => {
console.log(res)
})
})
现在,它会将文件移动到其他位置,但不会删除当前位置。也就是说,在完成我的代码后,这就像复制一个文件,而不是移动它。您使用的代码片段只删除第一个父级 为了正确删除所有父项,您必须在代码中添加以下行:
var previousParents = res.result.parents.join(',');
调用update
方法时,必须删除以前的父项
:
removeParents: previousParents,
参考文献