I want to use Execution api in app script to call another app script, but I see nowhere some examples to do that.
I've developed the app script api, but I don't know how to make the call in app script.
I need too to have an example to implement the oauth in this script to be able to access the app script api.
Someone can help me ?
Thanks
You may want to check this OAuth2 for Apps Script which is a library for Google Apps Script that provides the ability to create and authorize OAuth2 tokens as well as refresh them when they expire. This library uses Apps Script's new StateTokenBuilder and /usercallback endpoint to handle the redirects.
Related
It is possible to call Google Apps Scripts API directly from a Google Cloud Function? If so, how to call the script functions without requesting an Oauth permission to get the authentication token?
My motivation is using Cloud Scheduler to invoke some functions of the Google Apps Script regularly (the time-based triggers on Google App Scripts don't have the sufficient resolution for my project).
You don't need to publish the Apps Script Web App as an API, you can publish it as a plain Web App, which doesn't need to go through the OAuth process in order to trigger either the doGet() or doPost() functions. doGet() is triggered to run from a GET request to the published URL of the Web App, and doPost() is triggered by a POST request. You'd need to publish the Web App to be accessible to anyone. If you make a POST request, and send a password in the payload request, that could be a way to verify that the request is coming from your code. The payload will be inside of the event object. The event object is typically denoted by the letter "e".
function doPost(e) {
For information about the event object see:
https://developers.google.com/apps-script/guides/web?hl=en#request_parameters
I noticed that the Google Apps Script editor uses a Bearer token to make requests for a lot of things, that got me thinking: Is it possible to do all functions that are done with the google apps script with the google API on your own server? What is the essential difference? Just the fact that google apps script runs on google servers, while with the google API you would need to create your own servers?
For example many of the document functions, which I thought could only be done with the API, turns out can be found here https://developers.google.com/docs/api/reference/rest/v1/documents/request#InsertInlineImageRequest
so whats the essential difference?
Just the fact that google apps script runs on google servers, while with the google API you would need to create your own servers?
Yes. There are advantages to both methods:
API:
It's a rest API. You can use your own language(eg: Python) in your servers.
The api is more inclusive. There are stuff which can be done with the api, which cannot be accomplished with apps script.
User can set limited scopes for using API.
For example, at Drive API, https://www.googleapis.com/auth/drive.file can be used for Drive API. The same cannot be done with DriveApp of apps script.
Process cost of API is lower than that of the built-in methods for Google Apps Script1 2
Apps script:
No server on your side
Triggers. You can set up functions to run onEdit,onOpen or at a specific time.
Deep integration with Google apps: Sidebars/modal dialogs can only be done with apps script.
All methods of the api can be accessed indirectly through the bearer token.
Authorization/authentication is taken care of by apps script. You don't need to set up oauth.
Is there a way to run a google app script from a different app script?
im just getting into google app scripts and i couldnt find anything on the internet
It seems like you are looking for libraries functionality in Google App Script. Documentation
You can save a version of the script that you have the functions in it, and import the functions on to a second script file through menu>resources>libraries. You need to use script id for importing libraries, which you can find from menu>File>Project properties>Script ID
You can then execute the function using the script file name as the reference.
You can use the Apps Script API, you may find this helpful Executing Functions using the Apps Script API
"The Apps Script API provides a scripts.run method that remotely executes a specified Apps Script function"
You can call google app script form javascript or web page.
You have to implement doGet(or post) and publish your google app script.
I found good example.
Cheers.
I am trying to connect to an API using an oauth 1.0a signature for Google Script. I am looking for the functions and libraries to use in the Google Script.
Based from this documentation, APIs that act on behalf of a user usually require authorization, often using the OAuth protocol. Apps Script doesn't provide built-in support for the protocol, but there are open source libraries you can use to perform the OAuth flow and send the credentials with your requests.
Check this OAuth1 for Apps Script which is compatible with OAuth 1.0 and 1.0a.
OAuth1 for Apps Script is a library for Google Apps Script that provides the ability to create and authorize OAuth1 tokens. This library uses Apps Script's new StateTokenBuilder and /usercallback endpoint to handle the redirects.
Note: OAuth1 for Google APIs is deprecated and scheduled to be shut down on April 20, 2015. For accessing Google APIs, use the Apps Script OAuth2 library instead.
I have Google spreadsheet with script attached to it (with the Tools->Script Editor tool).
I want to call one of script function from external Android App. Is it possible? Should I use Spreadsheet API?
Unfortunately, you cannot directly call your script from any external application.
However, you can change it to be a web application, then invoke it via an HTTP GET or POST from almost anywhere, including an Android app.
Insert new rows into Google Spreadsheet via cURL/PHP - HOW? provides an example of a web app that you could adapt.
Should I use Spreadsheet API?
Your question doesn't actually say what it is you want to do, so the answer is "it depends". You still won't be able to invoke an embedded script using the Spreadsheet API, but you will be able to read and write spreadsheet content.
Obviously the answer depends on your usecases, but have you checked the Google Appscript API?
As stated it
provides methods to remotely execute Apps Script functions