abc.dat我使用下面的脚本来获取通过我的 Apps 脚本项目生成的文件blob 。有了 Drive 服务,这一切就变得很简单。使用的 oauthScope 是https://www.googleapis.com/auth/drive.readonly
function ReadData() {
var files;
var folders = DriveApp.getFoldersByName("Holder");
if (folders.hasNext()) {
var folder = folders.next();
var files = folder.getFiles();
while (files.hasNext()){
file = files.next();
if(file.getName()=='abc.dat'){
var content = file.getBlob().getDataAsString();
return content;
}
}
}
return '';
}
Run Code Online (Sandbox Code Playgroud)
为了减少身份验证范围,现在我正在修改代码以完全删除oauthScopehttps://www.googleapis.com/auth/drive.readonly并仅使用https://www.googleapis.com/auth/drive.fileoauthScope。
使用 Drive api,我没有找到获取文件 blob 的直接方法。我使用下面的脚本来获取 Word 文档文件的 blob。但它不适用于 .dat 文件并出现错误fileNotExportable, Export only supports Docs Editors files, code 403
function getBlob(fileID, format){
var url = …Run Code Online (Sandbox Code Playgroud)