This is a Google Apps Script library for creating, updating and exporting Google Apps Script project of the standalone type using Drive API. In this case, Apps Script API is not used.
I cannot take responsibility for the problems occurred by this library. So when you use this library, please use it by according to your own decision and at your own responsibility.
This GAS library updates the existing standalone Google Apps Script project. So when you use the wrong object, the existing script is deleted. PLEASE BE CAREFUL THIS. So when you use the update method in this library, I would like to recommend to test using a sample Google Apps Script project.
I had reported "Drive API cannot create Google Apps Script project no longer" before. Ref About this, I had reported the future request. Ref At July 30, 2020, I could confirm that the Google Apps Script project of the standalone type got to be able to be created by multipart/form-data
using Drive API again. Ref This is a good news for me. By this, in order to use this with Google Apps Script, I created this library. Because in this case, when the update method is used, the special scope of https://www.googleapis.com/auth/drive.scripts
is required. So I thought that when this is published as the Google Apps Script library, this will be useful for users.
- In this library, only the Google Apps Script project of the standalone type can be used. When you want to manage the container-bound script type, please use Google Apps Script API. Ref
I sincerely hope this library is useful for you.
Method | Description |
---|---|
getProject(fileId, fields) | Get standalone Google Apps Script project. fileId is the file ID of standalone Google Apps Script project. |
createProject(object) | Create new standalone Google Apps Script project. In this case, the script can be included. |
updateProject(object) | When you use this, PLEASE BE CAREFUL. Please test this method using a sample Google Apps Script. Update the existing standalone Google Apps Script project. |
1to51j1yqDvtTrJIoHzgOffCnZOK9MTCcSkky6niwRJlTLTNpxIfj3bI-
- Open Script Editor. Click as follows:
- -> Resource
- -> Library
- -> Input the Script ID in the text box. The Script ID is
1to51j1yqDvtTrJIoHzgOffCnZOK9MTCcSkky6niwRJlTLTNpxIfj3bI-
. - -> Add library
- -> Please select the latest version
- -> Developer mode ON (Or select others if you don't want to use the latest version)
- -> The identifier is "
GASProjectApp
". This is set under the default.
You can read more about libraries in Apps Script here.
Please use this library with enabling V8 runtime.
In this library, Drive API is used. So please enable Drive API at Advanced Google services.
This library uses the following scope. This is installed in the library, and nothing further is required from the user.
https://www.googleapis.com/auth/drive
https://www.googleapis.com/auth/drive.scripts
https://www.googleapis.com/auth/script.external_request
This library also uses the following GAS library.
This method is used for retrieving the standalone Google Apps Script project.
function myFunction() {
const fileId = "###"; // Please set the file ID of the standalone Google Apps Script project.
const res = GASProjectApp.getProject(fileId);
const str = res.getContentText();
console.log(str);
}
- This library returns Class HTTPResponse. Ref
fileId
: File ID of standalone Google Apps Script project.fields
: fields values of the method of "Files: export" in Drive API v3. Ref In the current stage, the result value is the same with and withoutfields: "*"
.
This method is used for creating new standalone Google Apps Script project. In this case, the script can be included.
function myFunction() {
const object = {
metadata: {
name: "sample project", // This is the filename of created Google Apps Script project.
parents: ["###"], // This is a parent folder of created Google Apps Script project.
},
body: {
files: [
{
name: "Code",
type: "server_js",
source: 'function sample() {\n console.log("sample")\n}',
},
],
},
fields: "id, name",
};
const res = GASProjectApp.createProject(object);
const str = res.getContentText();
console.log(str);
}
- This library returns Class HTTPResponse. Ref
metadata
: This is the metadata of the method of "Files: create" in Drive API v3. Refbody
: When you want to include the script when new Google Apps Script project is created, please use this. About the detail structure ofbody
, you can confirm the retrieved value usinggetProject
method. Ref In this case, even whenappsscript.json
is not used, the default values are used. But in my environment, the default timezone wasAmerica/Los_Angeles
. About this, I had already reported. But in the current stage, this is still not resolved. Ref So please be careful this.fields
: fields values of the method of "Files: create" in Drive API v3. Ref
This method is used for updating the existing standalone Google Apps Script project.
When you use this, PLEASE BE CAREFUL. Please test this method using a sample Google Apps Script.
function myFunction() {
const object = {
fileId: "###", // Please set the file ID of the existing standalone Google Apps Script project.
metadata: {
name: "updated filename",
},
body: {
files: [
{
id: "###", // Please set the ID of each file in Google Apps Script project.
name: "Code",
type: "server_js",
source: 'function sample() {\n console.log("updated")\n}',
},
],
},
fields: "name",
};
const res = GASProjectApp.updateProject(object);
const str = res.getContentText();
console.log(str);
}
- This library returns Class HTTPResponse. Ref
metadata
: This is the metadata of the method of "Files: create" in Drive API v3. Refbody
: When you want to include the script when new Google Apps Script project is created, please use this. About the detail structure ofbody
, you can confirm the retrieved value usinggetProject
method. Ref- It seems that
id
is required. Thisid
can be retrieved by thegetProject
method. Ref Thisid
cannot be retrieved with Apps Script API. Please be careful this.
- It seems that
fields
: fields values of the method of "Files: update" in Drive API v3. Ref
If you have any questions or comments, feel free to contact me.
-
v1.0.0 (July 31, 2020)
- Initial release.