I'm trying to find a way to run Google App Script code that's hosted on GHE. I found somewhere that you could get the script as a text string and use eval() to execute it as code, however I've read that it's a very unsecure way to do it and it shouldn't be done. Does anyone know any alternatives ways to run hosted code on Google App Script?
You could:
use this extension: https://chrome.google.com/webstore/detail/google-apps-script-github/lfjcgcmkmjjlieihflfhjopckgpelofo
use git and clasp CLI to push your code to your apps script project
From your specifications, I understand that you want to both host the script in GitHub Enterprise (GHE) and run it from there.
Even though Apps Script API offers a good range of functionalities such as executing functions from your App remotely it is not the best option for this scenario.
With clasp you can also write Apps Script functions remotely but eventually they have to be pushed to an Apps Script project.
So, after considering these limitations I think the best option you would have is to use the right Google API in your script (such as Gmail API for example). Its functional code can all be hosted and run from your application without the need of Apps Script projects and these APIs offer the same and extended functionalities than those offered by Apps Script.
Related
Purpose:
To do the installation on Google Apps Script Editor. So that...
I can install npm.
Problem:
I don't know how to do the installation on Google Apps Script Editor.
I feel this is a very beginner question. But I could not find any solution on the web. Thank you for reading.
[Console]
function myFunction() {
npm install - s node - binance - api
});
}
You cannot install anything on Google Apps Script.
You can use external script with , check if node-binance-api maintainer offers that.
FYI, the error message you see in GAS Execution log means the editor could not save your script because of syntax errors. Which is absolutely normal because you are not writing Javascript.
While both Google Apps Scrpt and NodeJS leverage Javascript, they each have services and APIs with implementations unique to their respective platforms.
The only way you can ensure that a NodeJS library will be compatible with Apps Script is if its written in the subset of Javascript supported by Apps Script. Unfortunately that's not the case for the node-binance-api package, it uses a lot of NodeJS specific features. You'd have to do some heavy code refactoring to make it work with Apps Script, assuming you can find analogs for those NodeJS features.
A better approach, in my opinion, is to leverage the Binance REST API directly. You can find documentation for the Binance REST API linked below:
https://binance-docs.github.io/apidocs/spot/en/#introduction
I'm working with apps script and the plivo api (https://www.plivo.com/docs/sms/api/message#list-all-messages). I'd like to be able to use the plivo node sdk (https://www.plivo.com/docs/sdk/server/node-sdk/) inside apps script. Is there a way to install this or use this from github or some other source directly?
Answer
In a summary you can't install or use plivo by using Apps Script.
You can use your own libraries or a shared library. Third party (external and not shared) libraries in Google Apps Script are not allowed directly.
As per the Google Apps Script documentation says Google Apps Script is a rapid application development platform that makes it fast and easy to create business applications that integrate with G Suite. Apps Script goal is mainly interact with other Google Services/APIs.
Why using third party libraries is not allowed/recommended?
It's possible to use the eval and UrlFetchApp.fetch() function in order to get the content of a specific JS and execute it like:
eval(UrlFetchApp.fetch('http://URL/javascript.js').getContentText());
However, it's adding more computing time when it comes to run an Apps Script and depending on your kind of user there's a limit to successfully execute a script.
External services like plivo or another VOIP services are not allowed due to the reasons I mentioned above. As a workaround I'd suggest to take a look into GCP products like App Engine or Compute Engine and make use of your third party library from there.
Scripting on google's IDE is a big pain, it's very laggy and it just sucks.
How can I make the google script editor work on my PC?
I tried downloading this Clasp
Also I added a library from google to javascript.
but when I run it it gives me this error:
var ss = SpreadsheetApp.getActiveSpreadsheet();
^
ReferenceError: SpreadsheetApp is not defined
How can I fix this?
What I'm basically trying to do with this script is to send an email based on a bunch of conditions on a google sheets.
Solution
In order to be able to run an Apps Script project remotely from your local machine, you need to use the clasp command run as you will be required to also use some kind of authorization (you will basically need to connect your local project to your remote Apps Script project and verify it is you the one trying to run it).
Here is a complete guide on how to use this command but just to summarise a bit you basically will need to set up a Project ID and create an OAuth Client ID to then be able to login using the credentials obtained from it clasp login --creds creds.json1.
This is an example of running a function using the command run:
clasp run 'functionName'
I hope this has helped you. Let me know if you need anything else or if you did not understood something. :)
Adding the google-apps-script library to webstorm might also help you out.
Follow the instructions here, but search for "google-apps-script" in the download library modal. Instead of "chrome" which is what this article is about.
How do I use WebStorm for Chrome Extension Development?
You'll then be able to create *.gs files. Open them as javascript.
Question:
Can I add the authorization part of my google sheets add-on into my add-on's code or does it need to be a separate thing? What would that code look like? If adding the authorization process into the google app script isn't an option, what would be the next best option and what would that look like?
Premise:
I'm very new to coding or working with an API, google app script, and google cloud platform. I have looked over Google's documentation a dozen times and I'm still unsure how to actually implement the authorization process. Using the HTTP/REST option looks like the best option but I'm really not sure. I've gotten the clientID, secret, URI, etc... that would be required but I don't know where I put that information. Does the code need to be on my website? If so, what would that look like or where can I go to learn more about it?
Thank you in advance!
Approach
When using Apps Script you won't need to insert your credentials anywhere. The Auth flow is managed by the Apps Script environment. Every time you will need extra permissions to run your script, the environment will prompt for your authorization. This will generally require a normal login to the google account you want to use to authorize your script.
Using Google APIs on Apps Script can be done using two different patterns:
Pattern 1: Built-in Google Services
You can use the Apps Script scaffold G Suite Apps classes to work on G Suite Documents, Sheets, Forms, Slides and more. This will feel like programming with native classes and interfaces than using an over-the-internet API.
Pattern 2: Advanced Google Services
Advanced services are essentially thin wrappers around the Google APIs. They You must enable an advanced service before you can use it in a script. To enable the Advanced Services visit the guide here
References:
Built-in Google Services
Advanced Google Services
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.