简体   繁体   中英

I created a Json file with Google Apps Script, I don't want to rewrite the URL, I want to overwrite the file

Situation

I have created a Json file with Google Apps Script.

I have set up a trigger to update new information. The URL changes because it is a new save.

I'm loading a Json file from elsewhere, specifying it by URL. When the URL changes, the file cannot be loaded.

Question

I do not want to rewrite the URL.

I want to overwrite and save the file. It would be helpful if you could tell me how to update the json file without changing the URL.

The way to fix the URL and save the json as a new file is also fine. I checked this one and only found information on web apps.

What I tried

I googled in English and Japanese with no favorable results.

I belive it can be done this way:

function update_json() {
  var file_ID = '1JLnR-DSZHjD9_VsOUoo30UhpTqPQA_uN'; // ID of your JSON file
  var new_conents = `{'a': 'a', 'b': 'b'}`;
  var blob = Utilities.newBlob(new_conents);
  Drive.Files.update({}, file_ID, blob);
}

Make sure that 'Drive API' service is enabled in Script Editor:

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM