Gapi.client.drive.files.update() 返回错误 "Parse Error"

Gapi.client.drive.files.update() Returning error "Parse Error"

使用 google api,我必须编写本质上相同但产生不同结果的代码集。

两者都只接受一个 fileId 和两个 parentId,一个要删除,一个要添加 google api。它本质上是对 google 驱动器中文件的移动操作。有效的代码只需要 (from, to, file) => {} 的签名,而没有的代码将在 Google Picker Call 的回调中传递给字段。 (Link to Picker API Docs)

第一个 returns 成功,第二个得到 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));
        });
    }
}

我需要更多信息来解决这个问题吗?

工作最终示例

function folderSelectedCallback(folderData, fileData) {
    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) => {

            const options = {
                addParents: folder.id,
                removeParents: (typeof f.parentId !== 'undefined') ? f.parentId : '',
                fileId: f.id
            };

            gapi.client
                .request({
                    path: `drive/v3/files/${options.fileId}`,
                    method: 'PATCH',
                    params: options,
                    body: options
                })
                .then((response) => console.log(response))
                .catch((err) => console.error(err));
        });
    }
}

出于某种原因,以这种方式使用 gapi.client.request 可以正常工作。