Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Script openById don't work?

this is the code i wrote:

function importEventData(){
  var dFile = DocsList.getFileById("0Ar2YhVnsK7LLdGVrUFdpRUVQTHJ0aG1SVkp6V0JMMkE");
  var text = DocumentApp.openById("0Ar2YhVnsK7LLdGVrUFdpRUVQTHJ0aG1SVkp6V0JMMkE").editAsText().getText();
  return text;
};

The first line of the function works. But unfortunatly at the second line the google compiler stops and say: "Document is missing.(maybe it is deleted.)" Now I'm trying about several hours, search accross the web, but can't find the problem. The script has permissions to access my gDrive. Although I tried to get the id from the dFile.getId() function. But this produces the same string and the same error.

like image 443
kiroshiro Avatar asked Nov 12 '22 18:11

kiroshiro


1 Answers

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

You need to add .getBody() before .editAsText() because DocumentApp.openByID('id') returns a document class object and the editastext method only applies to the body object. This is seen here in Google's documentation: https://developers.google.com/apps-script/reference/document/document-app

like image 95
Ross Avatar answered Jan 04 '23 02:01

Ross