我有一个googleform,可以从用户那里收集excel文件并上传到云端硬盘。据我了解,我应该从excel文件传输到电子表格以打开并获取数据。因此,我使用Drive.Files.insert()
来转换文件,这需要脚本的其他批准。我在Google脚本上的资源>高级Google服务下启用了Google Drive API,并将此google脚本链接到google cloud项目。Google云端硬盘API也在Google云上启用了“ OAuth 2.0客户端ID”。但是我的脚本仍然无法通过google登录过程,只能返回带有google登录页面的word文件。
脚本:
var Blob01 = UrlFetchApp.fetch(thelink).getBlob();
var fileInfo = {
title: "test1",
mimeType: MimeType.GOOGLE_SHEETS,
"parents": [{
'id': FolderId
}],
};
Drive.Files.insert(fileInfo, Blob01, {convert: true});
OAuth设置:Google API的范围>> ../auth/drive和../auth/drive.file凭据:OAuth客户端ID >> Web应用程序google drive api已启用,并且凭据已添加为“ Google drive api”和“ Web浏览器”&“用户数据”]
预先感谢
当您使用UrlFetchApp
从云端硬盘获取文件时,将需要授权。这就是为什么您得到带有Google登录页面的Word文件。
[尝试改用DriveApp从Google云端硬盘目录中获取文件。例如,您可以使用.getFilesByName()
功能。
这里是您的用例示例:
var blob = DriveApp.getFilesByName("Excel.xlsx").next().getBlob(); // Assuming this file name is unique in your google drive
var file_ops = {
title: "test1",
mimeType: MimeType.GOOGLE_SHEETS,
"parents": [
{
"id": FolderId
}
]
};
Drive.Files.insert(file_ops, blob, {"convert": true});