【发布时间】:2019-02-20 16:01:18
【问题描述】:
使用 google api,我必须使用基本相同但产生不同结果的代码集。
两者都简单地接受一个fileId和两个parentId,一个要删除,一个要使用google api添加。它本质上是对谷歌驱动器中文件的移动操作。有效的代码只需要(from, to, file) => {} 的签名,而没有通过Google Picker 调用回调中的字段的签名。 (Link to Picker API Docs)
第一个返回成功,第二个 get 是来自 api 的响应,指出存在解析错误,关于可能导致解析错误的原因几乎没有。
示例:
工作示例
moveFile = (from, to, file) => {
return gapi.client.drive.files
.update({
addParents: to,
removeParents: from,
fileId: file,
})
.then((res) => {
logger.log(funcname, `Moved File: ${file} from ${from} to ${to}.`);
return res.result;
});
};
非工作示例
function folderSelectedCallback(folderData, fileData) {
//folderData and fileData both have the same structure
//{action: 'type of action',
//docs: [{Array Of Document Objects}],
//viewToken: [Array of unused data]}
//Docs Array Objects Structure (only used properties listed.)
//{ id: 'string ID of the File',
//parentId: 'string ID of the parent folder'}
if (folderData.action === 'picked') {
console.log('folderSelectedCallback(): called.');
console.log('File Data: ', fileData);
console.log('Folder Data: ', folderData);
const files = fileData.docs;
const folder = folderData.docs[0];
console.log(files);
console.log(folder);
files.forEach((f) => {
gapi.client.drive.files
.update({
addParents: to,
removeParents: from,
fileId: file,
})
.then((res) => {
console.log(funcname, `Moved File: ${file} from ${from} to ${to}.`);
return res.result;
}).catch(err => console.error(err));
});
}
}
我需要更多信息来解决这个问题吗?
【问题讨论】:
标签: javascript google-api google-drive-api google-picker