Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 1,000,000+ packages pre-installed, including gapi-nano with all npm packages installed. Try it out:

var gapiNano = require("gapi-nano")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

gapi-nano v1.0.1

a wrapper for Google API Client Library for using Google Apps Script REST Execution API

Summary

This is a wrapper for the Google API Client Library, providing opinionated syntactic sugar for client authentication and making requests to a Google Apps Script via the REST Execution API

See: https://developers.google.com/apps-script/guides/rest/quickstart/js

Basic Usage

In your html, include the browser build gapi-nano.js from the dist directory after https://apis.google.com/js/api.js

<script src="https://apis.google.com/js/api.js"></script>
<script src="/dist/gapi-nano.js"></script>

Then in another script below that, pass in some options to gapiNano.init to get started

<script>
  var options = {
    clientId: '[CLOUD PLATFORM CLIENT_ID]',
    discoveryDocs: ["https://script.googleapis.com/$discovery/rest?version=v1"],
    scope: '[SCOPE]',
    scriptId: '[SCRIPT_ID]'
  }

  gapiNano.init(options,function(signedIn){
    console.log("User signed in?", signedIn)

    gapiNano.run('sum',{a:1,b:2}).then(function(result){
      console.log('sum of 1 and 2 is', result)
    })

  })
</script>

Functions

init(options, authListener)undefined

init - loads and authenticates gapi client using Auth2

run(fName, parameters)Promise

run - calls a function from the script specified by scriptId option during init()

init(options, authListener) ⇒ undefined

gapiNano.init - loads and authenticates gapi client using Auth2

ParamTypeDescription
optionsobjectAuth2 options, including clientId and scope
authListenerfunction(optional) callback with a single boolean parameter, called whenever the authentication status changes

run(fName, parameters) ⇒ Promise

gapiNano.run - calls a function from the script specified by scriptId option during init()

Returns: Promise - a Promise object resolved with result of the function call

ParamTypeDescription
fNamestringthe name of the function
parametersobject(optional) the arguments passed to the function

Building Changes

To rebuild dist/gapi-nano.js from index.js, use the npm task:

$ npm run dist

Of course this requires browserify to be installed globally:

$ npm install -g browserify

Metadata

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free