问题
I have a neural network script that requires training data from a JSON file, is it possible to save a json file on google app scripts?
回答1:
You can use the Advanced Drive Service, which must be enabled.
From the Apps Script code editor:
- "Resources" menu
- "Advanced Google Services"
- Find "Drive API" in the list
- Click the button to turn it ON
In the past, you needed to also enable the Drive API in the Google Cloud Platform. But now you have two choices.
- Use the "default" Google Cloud project - You don't need to explicitly enable the Drive API in the Google Cloud Platform.
- Create a new "standard" Google Cloud project and associate it with your Apps Script project. You will need to enable the Drive API in the Google Cloud Platform.
If the Apps Script project is going to be something used by the general public, then you should create a "standard" Google Cloud project, and enable the Google Drive API in the Google Cloud Platform.
Code:
function saveAsJSON() {
var blob,file,fileSets,obj;
obj = {//Object literal for testing purposes
key:"value"
}
/**
* Creates a file in the users Google Drive
*/
fileSets = {
title: 'AAA_Test.json',
mimeType: 'application/json'
};
blob = Utilities.newBlob(JSON.stringify(obj), "application/vnd.google-apps.script+json");
file = Drive.Files.insert(fileSets, blob);
Logger.log('ID: %s, File size (bytes): %s, type: %s', file.id, file.fileSize, file.mimeType);
}
来源:https://stackoverflow.com/questions/52777524/how-to-save-a-json-file-in-google-apps-script