Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-apps-script/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google apps script 谷歌脚本openById don';不行?_Google Apps Script_Google Docs - Fatal编程技术网

Google apps script 谷歌脚本openById don';不行?

Google apps script 谷歌脚本openById don';不行?,google-apps-script,google-docs,Google Apps Script,Google Docs,这是我写的代码: function importEventData(){ var dFile = DocsList.getFileById("0Ar2YhVnsK7LLdGVrUFdpRUVQTHJ0aG1SVkp6V0JMMkE"); var text = DocumentApp.openById("0Ar2YhVnsK7LLdGVrUFdpRUVQTHJ0aG1SVkp6V0JMMkE").editAsText().getText(); return text; }; 函数的第

这是我写的代码:

function importEventData(){
  var dFile = DocsList.getFileById("0Ar2YhVnsK7LLdGVrUFdpRUVQTHJ0aG1SVkp6V0JMMkE");
  var text = DocumentApp.openById("0Ar2YhVnsK7LLdGVrUFdpRUVQTHJ0aG1SVkp6V0JMMkE").editAsText().getText();
  return text;
};
函数的第一行起作用。 但不幸的是,在第二行,谷歌编译器停下来说:“文档丢失了(可能被删除了)。” 现在我试了几个小时,在网上搜索,但是找不到问题。脚本具有访问我的gDrive的权限。 尽管我试图从dFile.getId()函数中获取id。但这会产生相同的字符串和相同的错误

var text = DocumentApp.openById("0Ar2YhVnsK7LLdGVrUFdpRUVQTHJ0aG1SVkp6V0JMMkE").getBody().editAsText().getText();

您需要在
.editAsText()
之前添加
.getBody()
,因为
DocumentApp.openByID('id')
返回一个文档类对象,而editAsText方法只应用于body对象。这可以在谷歌的文档中看到:

您的文档实际上是一个电子表格,因此只能访问“文档”的DocumentApp无法访问它。(我怎么知道?我尝试在浏览器中按URL打开文档-文档URL返回“未找到”,但电子表格URL启动了“请求权限”对话框。)是的,您似乎应该使用SpreadsheetApp.openById()。此外,当您在进行此项工作时,您应该知道DocsList服务已于2014年12月11日被弃用,并于2015年4月20日关闭。谷歌硬盘服务取代了它。