使用Google Apps Script为共享云端硬盘文件加自定义属性报错求助
问题解决:共享云端硬盘文件添加自定义属性报错修复
错误原因
调用Drive.Files.update时参数顺序错误:该方法的第三个参数应为媒体上传数据(mediaData),但你传入了配置选项对象{supportsAllDrives: true},导致系统误将其识别为文件内容上传,触发类型不匹配报错。
修复方案
正确的Drive.Files.update参数顺序是:resource, fileId, mediaData, options。由于仅需更新文件属性、无需上传文件内容,需将mediaData设为null,并把配置选项移至第四个参数位置。
修改后的代码
addCustomProperties(fileID, Customer_name, Process_Type, Priority); function addCustomProperties(fileID, customerName, processType, Priority) { var resource = { properties: { CustomerName: customerName, ProcessType: processType, Priority: Priority } }; // 修正参数顺序:添加null作为mediaData参数,将选项移至第四个位置 Drive.Files.update(resource, fileID, null, {supportsAllDrives: true}); }
额外注意事项
- 确保已在Google Apps Script编辑器中启用Drive API高级服务(编辑器菜单 > 资源 > 高级Google服务 > 找到Drive API并启用)
- 确认当前脚本拥有共享云端硬盘的编辑权限
内容的提问来源于stack exchange,提问作者Yunlong
相关产品推荐
相关产品推荐

