Google has released clasp, please use it instead.
As per the discussion in issue #86, it does not make sense for these two projects to co-exist. This project is locked into it's final version and will receive no future updates.
Happy scripting!
The easiest way to develop Google Apps Script projects
Using gapps, you can develop your Apps Script locally and push files to the Apps Script servers. This allows you to use any editor of your choice, version control, and other modern webdev patterns in to Apps Script development.
npm install -g node-google-apps-script
To use gapps you need access to your files on your Google Drive through the API provided by Google. To make this happen you have to create a Developer Console Project
.
You can do this one of two ways:
This is the easiest approach because you don't need to create a new project. You will use the default Developer Console Project API Project
, enable Google Drive and get credentials.
Resources > Cloud Platform Project...
otherwise, go to the Google Cloud PlatformAPI Project
: click on the blue button at the top and select (API Project - api-project-##########
) from the list.APIs & services
in the left nav and then select Library
Drive
and select the Google Drive API listing.Enable API
Create Credentials
, otherwise , go to Credentials
in the left menu, select Create credentials
and choose OAuth client ID
Project Name
i.e. My API access project
. This can always be changed later.Other
for the Application type
.Create
.Download as JSON
button to the right. Save these credentials to a location of your choosing; ~/Downloads
is fine.Use an independent Developer Console Project if the default API Project
is deleted, in use or if you want to keep permissions separated.
&authuser=1
to the end of the url to choose which account to login with. Note that authuser
is zero-indexed.Create a New Project
is selected and hit Continue
.Go to Credentials
.Project Name
i.e. My API access project
. This can always be changed later.Other
for the Application type
.Create
.Download as JSON
button to the right. Save these credentials to a location of your choosing; ~/Downloads
is fine.To return to this project later, select Resources
> Developer Console Project
while editing your script. Then click the link at the top of the dialog to open the Developer Console with this project selected.
gapps
This process will set up Google Drive authentication to allow uploading and importing of the Apps Script project.
gapps auth path/to/client_secret_abcd.json
i.e. gapps auth ~/Downloads/client_secret_1234567890-abcd.apps.googleusercontent.com.json
client_secret.json
credentials file.You can pass the option --no-launch-browser
to generate a url that will give you a code to paste back into the console. This is useful if you're using ssh to develop.
This proces will create gapps.config.json
and a sub-directory where all Apps Script project files will be downloaded to. You can either use an existing project or create a new one.
/d/
and before /edit
i.e. '//script.google.com/a/google.com/d/abc123-xyz098/edit?usp=drive_web'gapps init <fileId>
within your project directory i.e. gapps init abc123-xyz098
/d/
and before /edit
i.e. '//script.google.com/a/google.com/d/abc123-xyz098/edit?usp=drive_web'gapps init <fileId>
within your project directory i.e. example, gapps init abc123-xyz098
Start scripting and enjoy total freedom of your local dev environment and source control options! Create script files with a .gs
or .js
extension and html files with a .html
extension
Run gapps upload
from within your project directory. You should then be able to reload your Apps Script project in the browser and see the changes.
Check out Matt Hessinger's blog post: Advanced development process with apps
Usage: gapps auth [options] <path/to/client/secret.json>
Authorize gapps to use the Google Drive API
Options:
-b, --no-launch-browser Do not use a local webserver to capture oauth code
and instead require copy/paste of key returned in
the browser after authorization completes.
-p, --port [port] Port to use for webserver
Performs the authentication flow described in the quickstart above.
Usage: gapps init|clone <fileId> [options]
Initialize project locally. The external Apps Script project must exist.
Options:
-k, --key [key]
-s, --subdir [subdir]
-o, --overwrite
Creates gapps.config.json
, which contains information about your Apps Script project and downloads all project files into a subdirectory (default: src/
)
Usage: gapps upload|push
Upload back to Google Drive. Run from root of project directory
Upload the project to Google Drive. Sources files from ./src
or the
configured subdirectory.
Usage: gapps deployment oauth-callback-url
Get the OAuth Callback URL for a project
Returns the OAuth Callback URL required by most 3rd-party OAuth services.
Please submit any bugs to the Issues page. Pull Requests also welcome.
If you want to develop, clone down the repo and have at it! You can run npm link
from the root directory of the repo to symlink to your local copy. You'll have to uninstall the production version first npm uninstall -g node-google-apps-script
.
gapps
allows you to nest files in folders, but the Apps Script platform expects a flat file structure. Because of this, no files can have the same name, even if they are in separate directories. One file will overwrite the other, making debugging difficult.
Your add-on must be developed as a standalone script and tested within Doc or Sheet. This means that it cannot use certain functions of bound scripts, namely installable triggers. While testing within a Doc, you have access to the "Special methods" mentioned in the docs, though. If you followed the quickstart above, you should be set up correctly.
The Google Drive API frequently returns a 400 error without a helpful error message. Common causes for this are:
.js
or .gs
) is validated upon upload.Underscore
or OAuth2
) have been added to the Apps Script project~/.gapps
exists and has 4 values: client_id
, client_secret
, redirect_uri
, and refresh_token
Huge thanks to Shrugs for a massive PR that bumped this project to v1.0