Call an App script library from another web site - javascript

Good morning,
I have some functions to modify a google sheet file (with Apps Script) and I want to call them from my site, basically, I want to click on a form to send me to an excel sheet with some specific data (with a function already created), and I have no possibility to create or modify an existing database, it is a very closed environment (Zendesk).
I don't know how to implement it on a web that is not made with google services.
Thanks for your help.

The easier way to call a Google Apps Script function from an external app is by creating a web app using Google Apps Script, set to be executed as the owner.
I.E. the following is the code for a web app that call myFunction and return a string as response when is called by a HTTP GET request.
function doGet(){
myFunction();
return ContentService.createTextOutput('Put here your response');
}
You should make a web application deployment, set as be executed as you by anyone even anonymous. Then make the HTTP GET request by using the web application URL.
Instead of doGet you might use doPost to make your web app respond to HTTP POST requests. Also, you might use different settings, but you should provide the proper OAuth token.
For further details please read https://developers.google.com/apps-script/guides/web
Another option is to use the Google Apps Script API but this might require from to invest more time.

Related

Publishing data from an array to a google spread sheet

I am working on a project where I run a web page from a local server using Xampp. In the web page I have a button which when clicked produces an array of 24 elements. I want this array to be written to my online google sheet.
My Question:
1)Can I post data from a web page running on a local server like Xampp to an online server like google sheet?
2)If yes, then is it possible to do it with php and javascript without any jquery?
3)If it is possible please show me the right path.
I am new to web development. Please help me. Thank you in advance for helping.
Yes it is possible to post data from your localhost as long as you have an internet connection.
to do such things I recommend you to read Sheets API Guides
You will also find there a sample code to write data to a spreadsheet on this page
Still an API key is required for public spreadsheets for other requests you need to use OAuth 2.0 as told here
If the request requires authorization (such as a request for an individual's private data), then the application must provide an OAuth
2.0 token with the request. The application may also provide the API key, but it doesn't have to.
If the request doesn't require authorization (such as a request for public data), then the application must provide either the API key
or an OAuth 2.0 token, or both—whatever option is most convenient for
you.
also as an advice and if you know javascript you could use Google App Script to get Started, after validating the implementation of the library into your project and console you will find built-in functions.

Is it possible to grant a JavaScript app, r/w permission to a Google Sheets file, without the need for the app user to log in/have a Google account?

I have a Google Spreadsheet file and a JavaScript application, hosted using Google Firebase free plan – if that changes anything. I would like to grant my application a read/write permission to the file so that when a user, posts something using my app, it will be written to the SpreadSheet as a new line. I thought that should be a simple scenario but…
While I got the read part running, using the API_KEY, the writing part seems to require OAuth authentication - even if the file itself is 100% public…
In my scenario the application itself should be the one, authenticating to the Sheet API - not the user of that application.
So, is there any way around this? Or to somehow log-in using OAuth on the application level?
Please note: I know I could use Firebase here, but let’s just assume that for now, it is not an option.
My final solution was to use Google Apps Script instead of Google Sheets API, as described here:
https://stackoverflow.com/a/49459945/2384366
After publishing the scrip with the ‘Who has access to the app’ = ‘Anyone, even anonymous’ – I was able to use the doPost function to do exactly what I wanted.
Perhaps it’s not the best solutions – but it works (and frankly, gives us much more control).

Is it possible to connect your background script to mongoDB server? If Yes, How?

I am creating a google chrome extension. I have a background script from which I want to send and retrieve some data from MongoDB database. How do I do that? I'm new in chrome extension development.
YES. It's possible. But, It's not a good idea to expose a database to the public internet at all. Implement a REST like method in your backend code and authorize calls to it using some web standard auth scheme, such as OAuth or HTTP Basic auth. Hitting the DB directly is way too dangerous. You can receive/send data from DB accordingly. Saying That if you still want to go ahead here's a link to help you with that For full REST capabilities, consider using an external REST Interface such as Sleepy.Mongoose.

Secure access to 3rd party API from a Javascript app

I am creating a web app in Angularjs which displays data from a 3rd party API (json). This is not a free API, I have to pay based on the amount of calls made.
I am given an API key which I call like this:
https://apiservice.com?key=1234567&p1=x&p2=y
I want to ensure that my api key is used only by my web app, so I created a proxy on my server. Now my angular app calls my server like this:
https://myserver.com/myapiproxy/?p1=x&p2=y , the server makes the call to the api using the key that is kept on the server, and returns the json data to the client. This way the key is kept secret.
However there is currently nothing to stop somebody else from calling "myapiproxy" and get the data.
Is there a way to ensure that only my app gets the data and that others can not make calls to the api on my expense?
I searched for a few hours and I couldn't find a truly secure answer. HTTP referer is not a good answer because it can be easily spoofed.
Take a look at JSON Web Tokens - https://jwt.io/
It is a good way to secure your calls. It has angular module - https://github.com/auth0/angular-jwt
When user loads your app you can provide a token jenerate on the backend and store it in local storage.
Than on each api call you can check if this token is authentic.

Use Google Apps Script Execution API with API keys and Javascript

I want to create a web application for my client and use Google drive to store information.
Since it's impossibe to integrate a web application from google apps script in my own website I try to use Google Apps Script Execution API and Javascript to make the interaction between my website and Google Drive.
I find out some exemple like this one :
https://mashe.hawksey.info/2015/10/google-sheets-as-a-database-authenticated-insert-with-apps-script-using-execution-api/
I do be able to reproduce this example but it use an Auth authentification.
I would like to use Google Apps Script Execution API without Auth authentification but with simple API keys.
Is it possible ? And do you have an example to illustrate this.
Thank you for your help,
Yes you can do that. Check this guide about web deployment using apps script. You just need to run the web app as your own user (parameter Execute the app as). But you will only be able to get access to your own google Drive which may not be that useful. If you want to access others' people Drive then you must run the web app as the current user but this will prompt for permissions (the first time the user access your application).

Categories

Resources